Don't copy unknown number of args to buffer of fixed size in initGlobs()
authorJindrich Novy <jnovy@redhat.com>
Thu, 17 Apr 2008 07:01:28 +0000 (09:01 +0200)
committerJindrich Novy <jnovy@redhat.com>
Thu, 17 Apr 2008 07:01:28 +0000 (09:01 +0200)
tools/rpmcache.c

index 9d372ad..fd25b83 100644 (file)
@@ -443,24 +443,20 @@ static int ftsPrint(FTS * ftsp, FTSENT * fts, rpmts ts)
  */
 static void initGlobs(rpmts ts, const char ** argv)
 {
-    char buf[BUFSIZ];
+    char *buf = NULL;
     int i;
 
-    buf[0] = '\0';
     if (argv != NULL && * argv != NULL) {
        const char * arg;
        int single = (glob_pattern_p(argv[0], 0) && argv[1] == NULL);
-       char * t;
 
-       t = buf;
-       if (!single)
-           t = stpcpy(t, "@(");
+       if (!single) {
+           rstrcat(&buf, "@(");
+       }
        while ((arg = *argv++) != NULL) {
-           t = stpcpy(t, arg);
-           *t++ = '|';
+           rstrscat(&buf, arg, "|", NULL);
        }
-       t[-1] = (single ? '\0' : ')');
-       *t = '\0';
+       buf[strlen(buf)-1] = single ? '\0' : ')';
     }
 
     bhpath = rpmExpand("%{_bhpath}", NULL);
@@ -509,6 +505,7 @@ static void initGlobs(rpmts ts, const char ** argv)
            rpmlog(RPMLOG_DEBUG, "\t%d \"%s\"\n",
                i, bhglobs[i].patterns[0]);
     }
+    free(buf);
 }
 
 static rpmVSFlags vsflags = 0;