Avoid compressFilelist() stack overflow in pathological cases
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Jan 2008 14:18:55 +0000 (16:18 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Jan 2008 14:18:55 +0000 (16:18 +0200)
- allocate dirNames etc arrays on heap, not stack
- the arrays can be rather large and alloca isn't very friendly when it
  fails...

lib/legacy.c

index a856c4e..704af5a 100644 (file)
@@ -54,9 +54,9 @@ void compressFilelist(Header h)
     if (fileNames == NULL || count <= 0)
        return;
 
-    dirNames = alloca(sizeof(*dirNames) * count);      /* worst case */
-    baseNames = alloca(sizeof(*dirNames) * count);
-    dirIndexes = alloca(sizeof(*dirIndexes) * count);
+    dirNames = xmalloc(sizeof(*dirNames) * count);     /* worst case */
+    baseNames = xmalloc(sizeof(*dirNames) * count);
+    dirIndexes = xmalloc(sizeof(*dirIndexes) * count);
 
     if (fileNames[0][0] != '/') {
        /* HACK. Source RPM, so just do things differently */
@@ -106,6 +106,9 @@ exit:
     }
 
     fileNames = hfd(fileNames, fnt);
+    free(dirNames);
+    free(baseNames);
+    free(dirIndexes);
 
     xx = hre(h, RPMTAG_OLDFILENAMES);
 }