From 1ee3028a58e7c4a78491dd07a97feaecbdf5731f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jan 2023 12:52:22 +1030 Subject: [PATCH] stringbuilder: avoid overwriting end of buffer with nul terminator. Signed-off-by: Rusty Russell --- ccan/stringbuilder/stringbuilder.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ccan/stringbuilder/stringbuilder.c b/ccan/stringbuilder/stringbuilder.c index d34de811..8eb4ab42 100644 --- a/ccan/stringbuilder/stringbuilder.c +++ b/ccan/stringbuilder/stringbuilder.c @@ -22,7 +22,8 @@ static int stringbuilder_cpy( if (*str != s) { if (!s_len) s_len = strlen(s); - if (s_len > *str_sz) + /* Include nul term! */ + if (s_len >= *str_sz) return EMSGSIZE; strcpy(*str, s); } -- 2.39.2