teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame rpm-4.9.0-macro-self-undefine.patch

Panu Matilainen 23ac61
commit f4c79584d01c6394544c86c122d2f32f77a1d02d
Panu Matilainen 23ac61
Author: Michael Schroeder <mls@suse.de>
Panu Matilainen 23ac61
Date:   Wed May 18 09:04:40 2011 +0300
Panu Matilainen 23ac61
Panu Matilainen 23ac61
    Always copy macro source when expanding it
Panu Matilainen 23ac61
    - A macro can undefine itself, and unless we grab a copy of it we'll
Panu Matilainen 23ac61
      end up accessing already freed memory. Fixes a regression from
Panu Matilainen 23ac61
      commit ebc4ceaaeb8bb59019f4635471b28eb5f3eaaaa6 which assumed
Panu Matilainen 23ac61
      a copy is not always needed.
Panu Matilainen 23ac61
    
Panu Matilainen 23ac61
    Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 23ac61
Panu Matilainen 23ac61
diff --git a/rpmio/macro.c b/rpmio/macro.c
Panu Matilainen 23ac61
index 8ea4819..d79ef18 100644
Panu Matilainen 23ac61
--- a/rpmio/macro.c
Panu Matilainen 23ac61
+++ b/rpmio/macro.c
Panu Matilainen 23ac61
@@ -1022,12 +1022,12 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
Panu Matilainen 23ac61
     char *source = NULL;
Panu Matilainen 23ac61
 
Panu Matilainen 23ac61
     /* Handle non-terminated substrings by creating a terminated copy */
Panu Matilainen 23ac61
-    if (slen > 0) {
Panu Matilainen 23ac61
-	source = xmalloc(slen + 1);
Panu Matilainen 23ac61
-	strncpy(source, src, slen);
Panu Matilainen 23ac61
-	source[slen] = '\0';
Panu Matilainen 23ac61
-	s = source;
Panu Matilainen 23ac61
-    }
Panu Matilainen 23ac61
+    if (!slen)
Panu Matilainen 23ac61
+	slen = strlen(src);
Panu Matilainen 23ac61
+    source = xmalloc(slen + 1);
Panu Matilainen 23ac61
+    strncpy(source, src, slen);
Panu Matilainen 23ac61
+    source[slen] = '\0';
Panu Matilainen 23ac61
+    s = source;
Panu Matilainen 23ac61
 
Panu Matilainen 23ac61
     if (mb->buf == NULL) {
Panu Matilainen 23ac61
 	size_t blen = MACROBUFSIZ + strlen(s);