From: Ngie Cooper Date: Sun, 11 Dec 2016 01:59:03 +0000 (-0800) Subject: Fix several coverity issues with test_read_append_filter_wrong_program X-Git-Tag: v3.3.0~91^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45ad9b555145ded81c8d3b59202e9c8980a25929;p=thirdparty%2Flibarchive.git Fix several coverity issues with test_read_append_filter_wrong_program 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] --- diff --git a/libarchive/test/test_read_set_format.c b/libarchive/test/test_read_set_format.c index fb5e00474..b4f414fa2 100644 --- a/libarchive/test/test_read_set_format.c +++ b/libarchive/test/test_read_set_format.c @@ -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 }