From 2b9a4bf3b307870324715bab698204f286368cc0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Ganne?= Date: Mon, 11 Oct 2021 13:49:59 +0200 Subject: [PATCH] api: fix buffer overflow in vl_msg_replay_json MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit cJSON_Parse() and vlib_cli_output() expect a NULL-terminated C-string. Type: fix Fixes: 36217e3ca8a1ca2e7a341b6b44ffc25e6497191c Change-Id: Id9819314fcd332c6076d1330b3433885fff07e36 Signed-off-by: Benoît Ganne --- src/vlibmemory/vlib_api_cli.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vlibmemory/vlib_api_cli.c b/src/vlibmemory/vlib_api_cli.c index 268b682f09a..afd145fe620 100644 --- a/src/vlibmemory/vlib_api_cli.c +++ b/src/vlibmemory/vlib_api_cli.c @@ -785,6 +785,10 @@ vl_msg_read_file (FILE *f) while ((n = fread (buf, 1, bufsize, f))) vec_add (v, buf, n); + /* most callers expect a NULL-terminated C-string */ + if (v) + vec_add1 (v, 0); + return v; } -- 2.16.6