assertion_count(file, line);
if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
return (1);
+ if (v1 == NULL || v2 == NULL)
+ return (0);
failure_start(file, line, "%s != %s", e1, e2);
logprintf(" size %s = %d\n", ld, (int)l);
char *buff;
size_t buff_size;
size_t expected_count, actual_count, i, j;
- char **expected;
- char *p, **actual;
+ char **expected = NULL;
+ char *p, **actual = NULL;
char c;
int expected_failure = 0, actual_failure = 0;
return (0);
}
- /* Make a copy of the provided lines and count up the expected file size. */
- expected_count = 0;
+ /* Make a copy of the provided lines and count up the expected
+ * file size. */
for (i = 0; lines[i] != NULL; ++i) {
}
expected_count = i;
- expected = malloc(sizeof(char *) * expected_count);
- for (i = 0; lines[i] != NULL; ++i) {
- expected[i] = strdup(lines[i]);
+ if (expected_count) {
+ expected = malloc(sizeof(char *) * expected_count);
+ if (expected == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ return (0);
+ }
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
}
/* Break the file into lines */
++actual_count;
c = *p;
}
- actual = malloc(sizeof(char *) * actual_count);
- for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
- if (*p != '\0') {
- actual[j] = p;
- ++j;
+ if (actual_count) {
+ actual = calloc(sizeof(char *), actual_count);
+ if (actual == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
}
}
if (test_num < 0) {
printf("*** INVALID Test %s\n", *argv);
free(refdir_alloc);
+ free(testprogdir);
usage(progname);
return (1);
}
strncat(result,
"bsdcpio: file: large inode number truncated: "
"Numerical result out of range\n",
- sizeof(result) - strlen(result));
+ sizeof(result) - strlen(result) -1);
/* hardlink to above file. */
assertMakeHardlink("linkfile", "file");
strncat(result,
"bsdcpio: linkfile: large inode number truncated: "
"Numerical result out of range\n",
- sizeof(result) - strlen(result));
+ sizeof(result) - strlen(result) -1);
/* Symlink to above file. */
if (canSymlink()) {
strncat(result,
"bsdcpio: symlink: large inode number truncated: "
"Numerical result out of range\n",
- sizeof(result) - strlen(result));
+ sizeof(result) - strlen(result) -1);
}
/* Another file with different permissions. */
strncat(result,
"bsdcpio: file2: large inode number truncated: "
"Numerical result out of range\n",
- sizeof(result) - strlen(result));
+ sizeof(result) - strlen(result) -1);
/* Directory. */
assertMakeDir("dir", 0775);
strncat(result,
"bsdcpio: dir: large inode number truncated: "
"Numerical result out of range\n",
- sizeof(result) - strlen(result));
- strncat(result, "2 blocks\n", sizeof(result) - strlen(result));
+ sizeof(result) - strlen(result) -1);
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result) -1);
/* All done. */
fclose(filelist);
/* Verify that nothing went to stderr. */
if (canSymlink()) {
- strncat(result, "2 blocks\n", sizeof(result) - strlen(result));
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result) -1);
} else {
- strncat(result, "1 block\n", sizeof(result) - strlen(result));
+ strncat(result, "1 block\n", sizeof(result) - strlen(result) -1);
}
assertTextFileContents(result, "newc.err");
assertion_count(file, line);
if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
return (1);
+ if (v1 == NULL || v2 == NULL)
+ return (0);
failure_start(file, line, "%s != %s", e1, e2);
logprintf(" size %s = %d\n", ld, (int)l);
char *buff;
size_t buff_size;
size_t expected_count, actual_count, i, j;
- char **expected;
- char *p, **actual;
+ char **expected = NULL;
+ char *p, **actual = NULL;
char c;
int expected_failure = 0, actual_failure = 0;
return (0);
}
- /* Make a copy of the provided lines and count up the expected file size. */
- expected_count = 0;
+ /* Make a copy of the provided lines and count up the expected
+ * file size. */
for (i = 0; lines[i] != NULL; ++i) {
}
expected_count = i;
- expected = malloc(sizeof(char *) * expected_count);
- for (i = 0; lines[i] != NULL; ++i) {
- expected[i] = strdup(lines[i]);
+ if (expected_count) {
+ expected = malloc(sizeof(char *) * expected_count);
+ if (expected == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ return (0);
+ }
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
}
/* Break the file into lines */
++actual_count;
c = *p;
}
- actual = malloc(sizeof(char *) * actual_count);
- for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
- if (*p != '\0') {
- actual[j] = p;
- ++j;
+ if (actual_count) {
+ actual = calloc(sizeof(char *), actual_count);
+ if (actual == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (j = 0, p = buff; p < buff + buff_size;
+ p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
}
}
if (test_num < 0) {
printf("*** INVALID Test %s\n", *argv);
free(refdir_alloc);
+ free(testprogdir);
usage(progname);
return (1);
}
/* Count ACL entries in myacls array and allocate an indirect array. */
for (n = 0; myacls[n].name != NULL; ++n)
continue;
- marker = malloc(sizeof(marker[0]) * n);
- for (i = 0; i < n; i++)
- marker[i] = i;
+ if (n) {
+ marker = malloc(sizeof(marker[0]) * n);
+ if (marker == NULL)
+ return;
+ for (i = 0; i < n; i++)
+ marker[i] = i;
+ } else
+ marker = NULL;
/*
* Iterate over acls in system acl object, try to match each
}
static int
-acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name)
+acl_match(struct acl_t *acl, int type, int permset, int tag, int qual,
+ const char *name)
{
+ if (acl == NULL)
+ return (0);
if (type != acl->type)
return (0);
if (permset != acl->permset)
if (name == NULL) {
if (acl->name == NULL || acl->name[0] == '\0')
return (1);
+ return (0);
}
if (acl->name == NULL) {
if (name[0] == '\0')
return (1);
+ return (0);
}
return (0 == strcmp(name, acl->name));
}
if (name == NULL) {
if (acl->name == NULL || acl->name[0] == '\0')
return (1);
+ return (0);
}
if (acl->name == NULL) {
if (name[0] == '\0')
return (1);
+ return (0);
}
return (0 == strcmp(name, acl->name));
}
/* Command name only. */
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "gzip"));
assertEqualInt(1, cl->argc);
assertEqualString("gzip", cl->path);
assertEqualInt(ARCHIVE_OK, __archive_cmdline_free(cl));
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "gzip "));
assertEqualInt(1, cl->argc);
failure("path should not include a space character");
assertEqualInt(ARCHIVE_OK, __archive_cmdline_free(cl));
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl,
"/usr/bin/gzip "));
assertEqualInt(1, cl->argc);
/* A command line includes space characer. */
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "\"gzip \""));
assertEqualInt(1, cl->argc);
failure("path should include a space character");
/* A command line includes space characer: pattern 2.*/
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "\"gzip \"x"));
assertEqualInt(1, cl->argc);
failure("path should include a space character");
/* A command line includes space characer: pattern 3.*/
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl,
"\"gzip \"x\" s \""));
assertEqualInt(1, cl->argc);
/* A command line includes space characer: pattern 4.*/
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl,
"\"gzip\\\" \""));
assertEqualInt(1, cl->argc);
/* A command name with a argument. */
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "gzip -d"));
assertEqualInt(2, cl->argc);
assertEqualString("gzip", cl->path);
/* A command name with two arguments. */
assert((cl = __archive_cmdline_allocate()) != NULL);
+ if (cl == NULL)
+ return;
assertEqualInt(ARCHIVE_OK, __archive_cmdline_parse(cl, "gzip -d -q"));
assertEqualInt(3, cl->argc);
assertEqualString("gzip", cl->path);
file_close(struct archive *a, void *data)
{
struct mydata *mydata = (struct mydata *)data;
+ if (mydata == NULL)
+ return (ARCHIVE_FATAL);
file_switch(a, mydata, NULL);
free(mydata->filename);
free(mydata);
for (i = 0; filename != NULL;)
{
assert((mydata = (struct mydata *)calloc(1, sizeof(*mydata))) != NULL);
+ if (mydata == NULL) {
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
assert((mydata->filename =
(char *)calloc(1, strlen(filename) + 1)) != NULL);
+ if (mydata->filename == NULL) {
+ free(mydata);
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
strcpy(mydata->filename, filename);
mydata->fd = -1;
filename = reffiles[++i];
archive_entry_set_uid(e, 23);
/* Retrieve a stat structure. */
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
/* Check that the values match. */
assertEqualInt(pst->st_atime, 456789);
assertEqualInt(pst->st_ctime, 345678);
/* Changing any one value should update struct stat. */
archive_entry_set_atime(e, 456788, 0);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_atime, 456788);
archive_entry_set_ctime(e, 345677, 431);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_ctime, 345677);
archive_entry_set_dev(e, 122);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_dev, 122);
archive_entry_set_gid(e, 33);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_gid, 33);
archive_entry_set_ino(e, 233);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_ino, 233);
archive_entry_set_mode(e, 012344);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_mode, 012344);
archive_entry_set_mtime(e, 234566, 542);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_mtime, 234566);
archive_entry_set_nlink(e, 344);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_nlink, 344);
archive_entry_set_size(e, 123456788);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_size, 123456788);
archive_entry_set_uid(e, 22);
assert((pst = archive_entry_stat(e)) != NULL);
+ if (pst == NULL)
+ return;
assertEqualInt(pst->st_uid, 22);
/* We don't need to check high-res fields here. */
struct archive_entry *ae;
struct archive *a;
char *rawimage = NULL, *image = NULL, *tmp = NULL;
- size_t size, oldsize = 0;
+ size_t size = 0, oldsize = 0;
int i, q;
extract_reference_files(filesets[n].names);
continue;
}
}
+ if (size == 0)
+ continue;
image = malloc(size);
assert(image != NULL);
+ if (image == NULL)
+ return;
srand((unsigned)time(NULL));
for (i = 0; i < 100; ++i) {
/* Get the group name for group 0 and see if it makes sense. */
p = archive_read_disk_gname(a, 0);
- if (assert(p != NULL)) {
+ assert(p != NULL);
+ if (p != NULL) {
i = 0;
while (i < sizeof(zero_groups)/sizeof(zero_groups[0])) {
if (strcmp(zero_groups[i], p) == 0)
/* The default block size of afio is 5120. we simulate it */
size = (sizeof(archive) + 5120 -1 / 5120) * 5120;
- if (!assert((p = malloc(size)) != NULL))
+ assert((p = malloc(size)) != NULL);
+ if (p == NULL)
return;
memset(p, 0, size);
memcpy(p, archive, sizeof(archive));
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
skipping("%s writing not supported on this platform",
compression);
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
use_prog = (r == ARCHIVE_WARN && can_prog);
buff = malloc(buff_size);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
ae = archive_entry_new();
assert(ae != NULL);
assert(0 == stat(archive_entry_pathname(ae), &st));
assertEqualInt(st.st_size, 8 * buff_size);
f = fopen(archive_entry_pathname(ae), "rb");
- if (!assert(f != NULL))
+ assert(f != NULL);
+ if (f == NULL) {
+ free(buff);
return;
+ }
/* Check first block. */
assertEqualInt(buff_size, fread(buff, 1, buff_size, f));
buff = malloc(buff_size);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
ae = archive_entry_new();
assert(ae != NULL);
assert(0 == stat(archive_entry_pathname(ae), &st));
assertEqualInt(st.st_size, 8 * buff_size);
f = fopen(archive_entry_pathname(ae), "rb");
- if (!assert(f != NULL))
+ assert(f != NULL);
+ if (f == NULL) {
+ free(buff);
return;
+ }
/* Check 100-byte gap at beginning */
assertEqualInt(100, fread(buff, 1, 100, f));
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
if (r != ARCHIVE_OK && !use_prog) {
skipping("bzip2 writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
else {
skipping("gzip writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
}
buffsize = 10000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/* Test1: set "gzip:timestamp" option. */
else {
skipping("gzip writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
}
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
if (r == ARCHIVE_FATAL) {
skipping("lzip writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
assertEqualIntA(a, ARCHIVE_OK,
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
if (r == ARCHIVE_FATAL) {
skipping("lzma writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
assertEqualIntA(a, ARCHIVE_OK,
buffsize = 2000000;
assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
datasize = 10000;
assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
memset(data, 0, datasize);
/*
if (r == ARCHIVE_FATAL) {
skipping("xz writing not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
return;
}
assertEqualIntA(a, ARCHIVE_OK,
buff = malloc(buffsize);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
/* ISO9660 format: Create a new archive in memory. */
assert((a = archive_write_new()) != NULL);
buff = malloc(buffsize);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
memset(&fns, 0, sizeof(fns));
/*
fns.names = (char **)malloc(sizeof(char *) * fcnt);
assert(fns.names != NULL);
+ if (fns.names == NULL) {
+ free(buff);
+ return;
+ }
fns.alloc = fcnt;
/* Verify rockridge filenames. */
memset(nullb, 0, sizeof(nullb));
buff = malloc(buffsize);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
/* ISO9660 format: Create a new archive in memory. */
assert((a = archive_write_new()) != NULL);
if (r == ARCHIVE_FATAL) {
skipping("zisofs option not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
return;
}
assertEqualIntA(a, 0, archive_write_set_option(a, NULL, "pad", NULL));
buff = malloc(buffsize);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
/* ISO9660 format: Create a new archive in memory. */
assert((a = archive_write_new()) != NULL);
if (r == ARCHIVE_FATAL) {
skipping("zisofs option not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
return;
}
assertEqualIntA(a, 0, archive_write_set_option(a, NULL, "pad", NULL));
memset(nullb, 0, sizeof(nullb));
buff = malloc(buffsize);
assert(buff != NULL);
+ if (buff == NULL)
+ return;
/* ISO9660 format: Create a new archive in memory. */
assert((a = archive_write_new()) != NULL);
if (r == ARCHIVE_FATAL) {
skipping("zisofs option not supported on this platform");
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
return;
}
assertEqualIntA(a, 0, archive_write_set_option(a, NULL, "boot", "boot.img"));
assertion_count(file, line);
if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
return (1);
+ if (v1 == NULL || v2 == NULL)
+ return (0);
failure_start(file, line, "%s != %s", e1, e2);
logprintf(" size %s = %d\n", ld, (int)l);
char *buff;
size_t buff_size;
size_t expected_count, actual_count, i, j;
- char **expected;
- char *p, **actual;
+ char **expected = NULL;
+ char *p, **actual = NULL;
char c;
int expected_failure = 0, actual_failure = 0;
return (0);
}
- /* Make a copy of the provided lines and count up the expected file size. */
- expected_count = 0;
+ /* Make a copy of the provided lines and count up the expected
+ * file size. */
for (i = 0; lines[i] != NULL; ++i) {
}
expected_count = i;
- expected = malloc(sizeof(char *) * expected_count);
- for (i = 0; lines[i] != NULL; ++i) {
- expected[i] = strdup(lines[i]);
+ if (expected_count) {
+ expected = malloc(sizeof(char *) * expected_count);
+ if (expected == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
}
/* Break the file into lines */
++actual_count;
c = *p;
}
- actual = malloc(sizeof(char *) * actual_count);
- for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
- if (*p != '\0') {
- actual[j] = p;
- ++j;
+ if (actual_count) {
+ actual = calloc(sizeof(char *), actual_count);
+ if (actual == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
}
}
if (test_num < 0) {
printf("*** INVALID Test %s\n", *argv);
free(refdir_alloc);
+ free(testprogdir);
usage(progname);
return (1);
}
/* Edit that file with a lot more data and update the archive with a new copy. */
buff = malloc(buff_size);
assert(buff != NULL);
+ if (buff == NULL) {
+ free(p0);
+ return;
+ }
+
for (i = 0; i < (int)buff_size; ++i)
buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26];
buff[buff_size - 1] = '\0';