diff options
author | Michael Schroeder <mls@suse.de> | 2011-05-18 09:04:40 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-05-18 09:10:11 +0300 |
commit | f4c79584d01c6394544c86c122d2f32f77a1d02d (patch) | |
tree | 814c475c9455360da8f4dcbdf7725d5aa03bc4a1 /rpmio/macro.c | |
parent | 4f3aa7327083005ebc4fce90e517fc57cce5af3d (diff) | |
download | rpm-f4c79584d01c6394544c86c122d2f32f77a1d02d.tar.gz rpm-f4c79584d01c6394544c86c122d2f32f77a1d02d.tar.bz2 rpm-f4c79584d01c6394544c86c122d2f32f77a1d02d.zip |
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 ebc4ceaaeb8bb59019f4635471b28eb5f3eaaaa6 which assumed
a copy is not always needed.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
Diffstat (limited to 'rpmio/macro.c')
-rw-r--r-- | rpmio/macro.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/rpmio/macro.c b/rpmio/macro.c index 8ea481954..d79ef18bb 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -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); |