Dynamically allocate buffers in rpmGetPath()
authorPanu Matilainen <pmatilai@redhat.com>
Sat, 19 Apr 2008 10:42:04 +0000 (13:42 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Sat, 19 Apr 2008 10:42:04 +0000 (13:42 +0300)
- avoid unbounded copying to static sized buffer
- use rpmExpand() instead of expandMacros() which requires preallocated
  buffer when we've no idea of expanded size

rpmio/rpmfileutil.c

index 5b64d14..58b94a0 100644 (file)
@@ -512,29 +512,23 @@ char * rpmGenPath(const char * urlroot, const char * urlmdir,
 
 char * rpmGetPath(const char *path, ...)
 {
-    char buf[BUFSIZ];
-    const char * s;
-    char * t, * te;
     va_list ap;
+    char *dest = NULL, *res;
+    const char *s;
 
     if (path == NULL)
        return xstrdup("");
 
-    buf[0] = '\0';
-    t = buf;
-    te = stpcpy(t, path);
-    *te = '\0';
-
     va_start(ap, path);
-    while ((s = va_arg(ap, const char *)) != NULL) {
-       te = stpcpy(te, s);
-       *te = '\0';
+    for (s = path; s; s = va_arg(ap, const char *)) {
+       rstrcat(&dest, s);
     }
     va_end(ap);
-    (void) expandMacros(NULL, NULL, buf, sizeof(buf));
 
-    (void) rpmCleanPath(buf);
-    return xstrdup(buf);       /* XXX xstrdup has side effects. */
+    res = rpmExpand(dest, NULL);
+    free(dest);
+
+    return rpmCleanPath(res);
 }
 
 /* =============================================================== */