Always copy macro source when expanding it
- A macro can undefine itself, and unless we grab a copy of it we'll
end up accessing already freed memory. Fixes a regression from
commit ebc4ceaaeb
which assumed
a copy is not always needed.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
This commit is contained in:
parent
4f3aa73270
commit
f4c79584d0
|
@ -1022,12 +1022,12 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
|
|||
char *source = NULL;
|
||||
|
||||
/* Handle non-terminated substrings by creating a terminated copy */
|
||||
if (slen > 0) {
|
||||
source = xmalloc(slen + 1);
|
||||
strncpy(source, src, slen);
|
||||
source[slen] = '\0';
|
||||
s = source;
|
||||
}
|
||||
if (!slen)
|
||||
slen = strlen(src);
|
||||
source = xmalloc(slen + 1);
|
||||
strncpy(source, src, slen);
|
||||
source[slen] = '\0';
|
||||
s = source;
|
||||
|
||||
if (mb->buf == NULL) {
|
||||
size_t blen = MACROBUFSIZ + strlen(s);
|
||||
|
|
Loading…
Reference in New Issue