From 978c6a4715e7eb98018a8a7d3776552c72868ca2 Mon Sep 17 00:00:00 2001 From: Javid Khan Date: Thu, 2 Jul 2026 21:19:45 +0530 Subject: [PATCH] nul-terminate cookie read from control connection --- src/iperf_server_api.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 66401fa6b..80957aa91 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -199,6 +199,12 @@ iperf_accept(struct iperf_test *test) i_errno = IERECVCOOKIE; goto error_handling; } + /* + * The cookie is later handled as a NUL-terminated string (printed + * and copied into JSON output), but a peer can send COOKIE_SIZE + * non-NUL bytes, so make sure it is terminated before it is used. + */ + test->cookie[COOKIE_SIZE - 1] = '\0'; FD_SET(test->ctrl_sck, &test->read_set); if (test->ctrl_sck > test->max_fd) test->max_fd = test->ctrl_sck;