From a829125e3753942fde0e21e3901c4018c86a9408 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Sat, 17 Feb 2024 14:41:38 -0500 Subject: [PATCH] =?UTF-8?q?strings.h:=20Ensure=20ast=5Fstr=5Fbuffer(?= =?UTF-8?q?=E2=80=A6)=20returns=20a=200=20terminated=20string.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a dynamic string is created with an initial length of 0, `ast_str_buffer(…)` will return an invalid pointer. This was a secondary discovery when fixing #65. --- include/asterisk/strings.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 10eb011463..935c7e9236 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -753,7 +753,10 @@ char * attribute_pure ast_str_buffer(const struct ast_str *buf), * being returned; eventually, it should become truly const * and only be modified via accessor functions */ - return (char *) buf->__AST_STR_STR; + if (__builtin_expect(buf->__AST_STR_LEN > 0, 1)) { + return (char *) buf->__AST_STR_STR; + } + return ""; } )