]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstd: fix crash when not overwriting existing files 972/head
authorPádraig Brady <P@draigBrady.com>
Tue, 2 Jan 2018 15:17:32 +0000 (15:17 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 2 Jan 2018 15:24:09 +0000 (15:24 +0000)
This fixes the following crash:
  $ touch exists
  $ programs/zstd -r examples/ -o exists
  zstd: exists already exists; not overwritten
  Segmentation fault (core dumped)

* programs/fileio.c (FIO_compressMultipleFilenames):
Handle the case where we're not overwriting the destination.

Reported at https://bugzilla.redhat.com/1530049

programs/fileio.c

index b57ce14d2f32289f1cba0e39cddb958ea22434c7..f9c9087ba2ec1568dcc7a14994d9728bd91d36f9 100644 (file)
@@ -951,10 +951,14 @@ int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFile
     if (outFileName != NULL) {
         unsigned u;
         ress.dstFile = FIO_openDstFile(outFileName);
-        for (u=0; u<nbFiles; u++)
-            missed_files += FIO_compressFilename_srcFile(ress, outFileName, inFileNamesTable[u], compressionLevel);
-        if (fclose(ress.dstFile))
-            EXM_THROW(29, "Write error : cannot properly close stdout");
+        if (ress.dstFile==NULL) {  /* could not open outFileName */
+            missed_files = nbFiles;
+        } else {
+            for (u=0; u<nbFiles; u++)
+                missed_files += FIO_compressFilename_srcFile(ress, outFileName, inFileNamesTable[u], compressionLevel);
+            if (fclose(ress.dstFile))
+                EXM_THROW(29, "Write error : cannot properly close stdout");
+        }
     } else {
         unsigned u;
         for (u=0; u<nbFiles; u++) {