aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2016-12-12 02:12:51 +0000
committerEnji Cooper <ngie@FreeBSD.org>2016-12-12 02:12:51 +0000
commitf428c3b114eca361b2c069d987e95553368cd827 (patch)
tree0918071a759fc467d4a5dad38596a27e6d40e5c9
parent48de45414155afefbd9cffe45683257eb804f8ee (diff)
downloadsrc-f428c3b114eca361b2c069d987e95553368cd827.tar.gz
src-f428c3b114eca361b2c069d987e95553368cd827.zip
Merge PR to address libarchive/test coverity issues
Obtained from: libarchive (f9e3de49fb294901374e0c8c6c2ceaeea7b6d6c0)
Notes
Notes: svn path=/vendor/libarchive/dist/; revision=309865
-rw-r--r--libarchive/test/read_open_memory.c33
-rw-r--r--libarchive/test/test_fuzz.c17
-rw-r--r--libarchive/test/test_read_disk_directory_traversals.c1
-rw-r--r--libarchive/test/test_read_set_format.c8
4 files changed, 36 insertions, 23 deletions
diff --git a/libarchive/test/read_open_memory.c b/libarchive/test/read_open_memory.c
index f4162eb4bb49..2bb8d54751c7 100644
--- a/libarchive/test/read_open_memory.c
+++ b/libarchive/test/read_open_memory.c
@@ -86,21 +86,7 @@ static int
read_open_memory_internal(struct archive *a, const void *buff,
size_t size, size_t read_size, int level)
{
- struct read_memory_data *mine;
-
- mine = (struct read_memory_data *)malloc(sizeof(*mine));
- if (mine == NULL) {
- archive_set_error(a, ENOMEM, "No memory");
- return (ARCHIVE_FATAL);
- }
- memset(mine, 0, sizeof(*mine));
- mine->start = mine->p = (const unsigned char *)buff;
- mine->end = mine->start + size;
- mine->read_size = read_size;
- mine->copy_buff_offset = 32;
- mine->copy_buff_size = read_size + mine->copy_buff_offset * 2;
- mine->copy_buff = malloc(mine->copy_buff_size);
- memset(mine->copy_buff, 0xA5, mine->copy_buff_size);
+ struct read_memory_data *mine = NULL;
switch (level) {
case 3:
@@ -109,6 +95,20 @@ read_open_memory_internal(struct archive *a, const void *buff,
archive_read_set_open_callback(a, memory_read_open);
archive_read_set_skip_callback(a, memory_read_skip);
case 1:
+ mine = malloc(sizeof(*mine));
+ if (mine == NULL) {
+ archive_set_error(a, ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ memset(mine, 0, sizeof(*mine));
+ mine->start = mine->p = (const unsigned char *)buff;
+ mine->end = mine->start + size;
+ mine->read_size = read_size;
+ mine->copy_buff_offset = 32;
+ mine->copy_buff_size = read_size + mine->copy_buff_offset * 2;
+ mine->copy_buff = malloc(mine->copy_buff_size);
+ memset(mine->copy_buff, 0xA5, mine->copy_buff_size);
+
archive_read_set_read_callback(a, memory_read);
archive_read_set_close_callback(a, memory_read_close);
archive_read_set_callback_data(a, mine);
@@ -213,7 +213,8 @@ memory_read_close(struct archive *a, void *client_data)
{
struct read_memory_data *mine = (struct read_memory_data *)client_data;
(void)a; /* UNUSED */
- free(mine->copy_buff);
+ if (mine != NULL)
+ free(mine->copy_buff);
free(mine);
return (ARCHIVE_OK);
}
diff --git a/libarchive/test/test_fuzz.c b/libarchive/test/test_fuzz.c
index 602b894661cc..ff064c07d498 100644
--- a/libarchive/test/test_fuzz.c
+++ b/libarchive/test/test_fuzz.c
@@ -104,16 +104,19 @@ test_fuzz(const struct files *filesets)
}
if (!assert(size < buffsize)) {
free(rawimage);
+ rawimage = NULL;
continue;
}
} else {
for (i = 0; filesets[n].names[i] != NULL; ++i)
{
tmp = slurpfile(&size, filesets[n].names[i]);
- char *newraw = (char *)realloc(rawimage, oldsize + size);
+ char *newraw = realloc(rawimage, oldsize + size);
if (!assert(newraw != NULL))
{
free(rawimage);
+ rawimage = NULL;
+ free(tmp);
continue;
}
rawimage = newraw;
@@ -123,14 +126,21 @@ test_fuzz(const struct files *filesets)
free(tmp);
}
}
- if (size == 0)
+ if (size == 0) {
+ free(rawimage);
+ rawimage = NULL;
continue;
+ }
image = malloc(size);
assert(image != NULL);
if (image == NULL) {
free(rawimage);
+ rawimage = NULL;
return;
}
+
+ assert(rawimage != NULL);
+
srand((unsigned)time(NULL));
for (i = 0; i < 1000; ++i) {
@@ -162,6 +172,7 @@ test_fuzz(const struct files *filesets)
Sleep(100);
#endif
}
+ assert(f != NULL);
assertEqualInt((size_t)size, fwrite(image, 1, (size_t)size, f));
fclose(f);
@@ -195,7 +206,7 @@ test_fuzz(const struct files *filesets)
archive_read_close(a);
}
archive_read_free(a);
-}
+ }
free(image);
free(rawimage);
}
diff --git a/libarchive/test/test_read_disk_directory_traversals.c b/libarchive/test/test_read_disk_directory_traversals.c
index c16b0c65311a..1d48cdde1221 100644
--- a/libarchive/test/test_read_disk_directory_traversals.c
+++ b/libarchive/test/test_read_disk_directory_traversals.c
@@ -1327,6 +1327,7 @@ test_callbacks(void)
if (assert((m = archive_match_new()) != NULL)) {
archive_entry_free(ae);
archive_read_free(a);
+ archive_match_free(m);
return;
}
diff --git a/libarchive/test/test_read_set_format.c b/libarchive/test/test_read_set_format.c
index fb5e0047443a..b4f414fa2bb2 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
}