X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fcmd-2-1.c;h=38381f894daad1662e10fad02550d9b5366ff623;hb=317eadef3cb6e74992824cad4c1193b6dc1e9fdf;hp=32a94386f3ef8171191f15cfcbc63de3ab6b2a5f;hpb=7591bab11eceedc6a0d1e02fd6f85592267a63b5;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/cmd-2-1.c b/src/bin/lttng-relayd/cmd-2-1.c index 32a94386f..38381f894 100644 --- a/src/bin/lttng-relayd/cmd-2-1.c +++ b/src/bin/lttng-relayd/cmd-2-1.c @@ -17,46 +17,60 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include -#include #include #include +#include +#include -#include "cmd-generic.h" #include "cmd-2-1.h" #include "utils.h" /* * cmd_recv_stream_2_1 allocates path_name and channel_name. */ -int cmd_recv_stream_2_1(struct relay_connection *conn, +int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload, char **ret_path_name, char **ret_channel_name) { int ret; struct lttcomm_relayd_add_stream stream_info; char *path_name = NULL; char *channel_name = NULL; + size_t len; - ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info)); - if (ret < 0) { - ERR("Unable to recv stream version 2.1"); + if (payload->size < sizeof(stream_info)) { + ERR("Unexpected payload size in \"cmd_recv_stream_2_1\": expected >= %zu bytes, got %zu bytes", + sizeof(stream_info), payload->size); + ret = -1; goto error; } + memcpy(&stream_info, payload->data, sizeof(stream_info)); - path_name = create_output_path(stream_info.pathname); + len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname)); + /* Ensure that NULL-terminated and fits in local filename length. */ + if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) { + ret = -ENAMETOOLONG; + ERR("Path name too long"); + goto error; + } + path_name = strdup(stream_info.pathname); if (!path_name) { PERROR("Path name allocation"); ret = -ENOMEM; goto error; } - + len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name)); + if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) { + ret = -ENAMETOOLONG; + ERR("Channel name too long"); + goto error; + } channel_name = strdup(stream_info.channel_name); if (!channel_name) { ret = -errno; - PERROR("Path name allocation"); + PERROR("Channel name allocation"); goto error; }