From 78aa171d6f64d9ba13ff2fbafb27248115ae430b Mon Sep 17 00:00:00 2001
From: Tilghman Lesher <tilghman@meg.abyt.es>
Date: Thu, 2 Apr 2009 15:14:22 +0000
Subject: [PATCH] Missed a common case for needing to extend the buffer.
 (closes issue #14716)  Reported by: sum  Patches:       
 20090402__bug14716.diff.txt uploaded by tilghman (license 14)  Tested by: sum

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@186021 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/strings.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/main/strings.c b/main/strings.c
index aecf4099ec..2e4b749c97 100644
--- a/main/strings.c
+++ b/main/strings.c
@@ -143,7 +143,8 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si
 		maxlen--;
 		(*buf)->__AST_STR_USED++;
 
-		if (dynamic && (!maxlen || (escapecommas && !(maxlen - 1)))) {
+		if ((ptr >= (*buf)->__AST_STR_STR + (*buf)->__AST_STR_LEN - 3) ||
+			(dynamic && (!maxlen || (escapecommas && !(maxlen - 1))))) {
 			char *oldbase = (*buf)->__AST_STR_STR;
 			size_t old = (*buf)->__AST_STR_LEN;
 			if (ast_str_make_space(buf, (*buf)->__AST_STR_LEN * 2)) {
-- 
GitLab