From 715e6fb12b68e1749ee78607ad032acea6bbc2a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 25 Apr 2018 14:57:29 -0400 Subject: [PATCH] Fix: relay_recv_metadata does not check for partial write MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- configure.ac | 1 + src/bin/lttng-relayd/main.c | 5 ++--- src/common/defaults.h | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 5173b1ea9..a99c0d3c5 100644 --- a/configure.ac +++ b/configure.ac @@ -366,6 +366,7 @@ _AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_AGENT_BIND_ADDRESS], [localhost]) _AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_CONTROL_BIND_ADDRESS], [0.0.0.0]) _AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_DATA_BIND_ADDRESS], [0.0.0.0]) _AC_DEFINE_QUOTED_AND_SUBST([DEFAULT_NETWORK_VIEWER_BIND_ADDRESS], [localhost]) +_AC_DEFINE_AND_SUBST([DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE], [134217728]) _AC_DEFINE_AND_SUBST([DEFAULT_ROTATE_PENDING_RELAY_TIMER], [200000]) # Command short descriptions diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 44ea6cdee..cf6d8ba23 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1808,7 +1808,7 @@ static int relay_recv_metadata(const struct lttcomm_relayd_hdr *recv_hdr, size_ret = write_padding_to_file(metadata_stream->stream_fd->fd, metadata_payload_header.padding_size); - if (size_ret < 0) { + if (size_ret < (int64_t) metadata_payload_header.padding_size) { ret = -1; goto end_put; } @@ -3068,8 +3068,7 @@ static int relay_process_control_receive_header(struct relay_connection *conn) conn->sock->fd, header.cmd, header.cmd_version, header.data_size); - /* FIXME temporary arbitrary limit on data size. */ - if (header.data_size > (128 * 1024 * 1024)) { + if (header.data_size > DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE) { ERR("Command header indicates a payload (%" PRIu64 " bytes) that exceeds the maximal payload size allowed on a control connection.", header.data_size); ret = -1; diff --git a/src/common/defaults.h b/src/common/defaults.h index e0f4438c8..fabcf0852 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -299,6 +299,10 @@ */ #define DEFAULT_INET_TCP_TIMEOUT 180 /* sec */ +/* Maximum payload size for a control connection */ + +#define DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE CONFIG_DEFAULT_NETWORK_RELAYD_CTRL_MAX_PAYLOAD_SIZE + /* * Default receiving and sending timeout for an application socket. */ -- 2.34.1