From: Sean Bright Date: Sat, 17 Feb 2024 19:41:38 +0000 (-0500) Subject: strings.h: Ensure ast_str_buffer(…) returns a 0 terminated string. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31ab82840b031b17643adf742b84cd2ed6924df2;p=thirdparty%2Fasterisk.git strings.h: Ensure ast_str_buffer(…) returns a 0 terminated string. 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. --- 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 ""; } )