]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix several coverity issues with test_read_append_filter_wrong_program
authorNgie Cooper <yanegomi@gmail.com>
Sun, 11 Dec 2016 01:59:03 +0000 (17:59 -0800)
committerNgie Cooper <yanegomi@gmail.com>
Sun, 11 Dec 2016 02:04:31 +0000 (18:04 -0800)
1. Ignore errors from fsetpos to mute complaint from Coverity
2. Make sure the first dup2 succeeds to quell complaints from Coverity
   about negative values being passed into the subsequent dup2 call.
3. Unconditionally close fd [3]. Although it's unlikely for freopen to
   fail, it can happen.. closing fd shouldn't be contingent on freopen's
   success.

CID: 1364318 [1], 1364322 [2], 1365233 [3]

libarchive/test/test_read_set_format.c

index fb5e0047443aac3c32784f5446c30fa5bac024a0..b4f414fa2bb2386609a4458b5cbdf89848fa5e1e 100644 (file)
@@ -219,8 +219,8 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
   /* bunzip2 will write to stderr, redirect it to a file */
   fflush(stderr);
   fgetpos(stderr, &pos);
-  fd = dup(fileno(stderr));
-  fp = freopen("stderr1", "w", stderr); 
+  assert((fd = dup(fileno(stderr))) != -1);
+  fp = freopen("stderr1", "w", stderr);
 #endif
 
   assert((a = archive_read_new()) != NULL);
@@ -238,10 +238,10 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
   if (fp != NULL) {
     fflush(stderr);
     dup2(fd, fileno(stderr));
-    close(fd);
     clearerr(stderr);
-    fsetpos(stderr, &pos);
+    (void)fsetpos(stderr, &pos);
   }
+  close(fd);
   assertTextFileContents("bunzip2: (stdin) is not a bzip2 file.\n", "stderr1");
 #endif
 }