From f0218c668a86d27ff8e9ae8df7199888c5633f59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 28 Feb 2018 16:26:11 -0500 Subject: [PATCH] Fix: fail on truncation of snapshot path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/consumer.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 5906cdca5..44dc35d6b 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -1460,6 +1460,16 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, if (ret < 0) { ret = -LTTNG_ERR_NOMEM; goto error; + } else if (ret >= sizeof(msg.u.snapshot_channel.pathname)) { + ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s/%s-%s-%" PRIu64 "%s\"", + sizeof(msg.u.snapshot_channel.pathname), + ret, output->consumer->dst.net.base_dir, + output->consumer->subdir, + output->name, output->datetime, + output->nb_snapshot, + session_path); + ret = -LTTNG_ERR_SNAPSHOT_FAIL; + goto error; } } else { ret = snprintf(msg.u.snapshot_channel.pathname, @@ -1472,7 +1482,16 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, if (ret < 0) { ret = -LTTNG_ERR_NOMEM; goto error; + } else if (ret >= sizeof(msg.u.snapshot_channel.pathname)) { + ERR("Snapshot path exceeds the maximal allowed length of %zu bytes (%i bytes required) with path \"%s/%s-%s-%" PRIu64 "%s\"", + sizeof(msg.u.snapshot_channel.pathname), + ret, output->consumer->dst.session_root_path, + output->name, output->datetime, output->nb_snapshot, + session_path); + ret = -LTTNG_ERR_SNAPSHOT_FAIL; + goto error; } + msg.u.snapshot_channel.relayd_id = (uint64_t) -1ULL; /* Create directory. Ignore if exist. */ -- 2.34.1