diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2009-02-16 23:48:54 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2009-02-16 23:48:54 +0000 |
commit | 76b100354d7d905cf7c3ebc998c28990eac6e923 (patch) | |
tree | 64f7842467af045be1cf9b4cd8e11a934d614fd4 | |
parent | f8a6cc1ebcb56092858d2d79ffb874abd3f5db58 (diff) |
Might want to update the buffer pointer after a realloc (or we crash)
(closes issue #14485)
Reported by: davevg
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@176360 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | main/strings.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/main/strings.c b/main/strings.c index 56bb5623d..bdf007fc3 100644 --- a/main/strings.c +++ b/main/strings.c @@ -131,6 +131,7 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si (*buf)->__AST_STR_USED++; if (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)) { /* If the buffer can't be extended, end it. */ @@ -138,6 +139,11 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si } /* What we extended the buffer by */ maxlen = old; + + /* Update ptr, if necessary */ + if ((*buf)->__AST_STR_STR != oldbase) { + ptr = ptr - oldbase + (*buf)->__AST_STR_STR; + } } } if (__builtin_expect(!(maxsrc && maxlen), 0)) { |