summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2014-08-20 17:04:49 +0000
committerasomers <asomers@FreeBSD.org>2014-08-20 17:04:49 +0000
commitab6d2528d2c28910838f5d9ea7728f114fa64c60 (patch)
tree9f97702700e2eb62ec4ed2e50e8376fedcfb7695 /sbin
parent01adfcd353e234439214159111d698f91fc2a59c (diff)
downloadFreeBSD-src-ab6d2528d2c28910838f5d9ea7728f114fa64c60.zip
FreeBSD-src-ab6d2528d2c28910838f5d9ea7728f114fa64c60.tar.gz
Misc fixes suggested by Coverity.
sbin/devd/tests/client_test.c * In the event that popen fails, don't dereference its return value. * Fix array overwrite in the stream and seqpacket tests. * Close sockets at the end of successful ATF tests. Reported by: Coverity scan CID: 1232019, 1232020, 1232029, 1232030 MFC after: 1 week Sponsored by: Spectra Logic
Diffstat (limited to 'sbin')
-rw-r--r--sbin/devd/tests/client_test.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sbin/devd/tests/client_test.c b/sbin/devd/tests/client_test.c
index 5e3acd0..dda9a89 100644
--- a/sbin/devd/tests/client_test.c
+++ b/sbin/devd/tests/client_test.c
@@ -58,6 +58,7 @@ create_two_events(void)
snprintf(destroy_cmd, nitems(destroy_cmd), "mdconfig -d -u %s", mdname);
destroy_stdout = popen(destroy_cmd, "r");
+ ATF_REQUIRE(destroy_stdout != NULL);
/* We expect no output */
ATF_REQUIRE_EQ(0, pclose(destroy_stdout));
}
@@ -105,7 +106,8 @@ ATF_TC_BODY(seqpacket, tc)
ssize_t len;
char event[1024];
- len = recv(s, event, sizeof(event), MSG_WAITALL);
+ /* Read 1 less than sizeof(event) to allow space for NULL */
+ len = recv(s, event, sizeof(event) - 1, MSG_WAITALL);
ATF_REQUIRE(len != -1);
/* NULL terminate the result */
event[len] = '\0';
@@ -118,6 +120,8 @@ ATF_TC_BODY(seqpacket, tc)
if (cmp == 0)
got_destroy_event = true;
}
+
+ close(s);
}
/*
@@ -160,7 +164,8 @@ ATF_TC_BODY(stream, tc)
ssize_t newlen;
char *create_pos, *destroy_pos;
- newlen = read(s, &event[len], sizeof(event) - len);
+ /* Read 1 less than sizeof(event) to allow space for NULL */
+ newlen = read(s, &event[len], sizeof(event) - len - 1);
ATF_REQUIRE(newlen != -1);
len += newlen;
/* NULL terminate the result */
@@ -174,8 +179,9 @@ ATF_TC_BODY(stream, tc)
destroy_pos = strstr(event, destroy_pat);
if (destroy_pos != NULL)
got_destroy_event = true;
-
}
+
+ close(s);
}
/*
OpenPOWER on IntegriCloud