[Git][NTPsec/ntpsec][master] Coverity warning cleanup.
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Dec 7 10:45:35 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
41dbe2da by Eric S. Raymond at 2015-12-07T05:44:13Z
Coverity warning cleanup.
Mostly new defecvts introduced by tests. One potential overrun found in the
Palisade refclock.
- - - - -
12 changed files:
- ntpd/ntp_intercept.c
- ntpd/ntp_io.c
- ntpd/ntp_util.c
- ntpd/refclock_palisade.c
- tests/libntp/calendar.c
- tests/libntp/caljulian.c
- tests/ntpdig/kod_file.c
- tests/ntpdig/packet_handling.c
- tests/ntpdig/packet_processing.c
- tests/ntpdig/utilities.c
- tests/unity/unity_fixture.c
- util/bumpclock.c
Changes:
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -293,7 +293,7 @@ intercept_leapsec_load_file(
bool force,
bool logall)
{
- bool loaded;
+ bool loaded = true;
if (mode != replay)
loaded = leapsec_load_file(fname, sb_old, force, logall);
=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -3484,6 +3484,7 @@ read_network_packet(
msghdr.msg_namelen = fromlen;
msghdr.msg_iov = &iovec;
msghdr.msg_iovlen = 1;
+ msghdr.msg_flags = 0;
msghdr.msg_control = (void *)&control;
msghdr.msg_controllen = sizeof(control);
rb->recv_length = recvmsg(fd, &msghdr, 0);
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -212,7 +212,7 @@ stats_config(
FILE *fp;
const char *value;
int len;
- double new_drift;
+ double new_drift = 0;
l_fp now;
time_t ttnow;
const char temp_ext[] = ".TEMP";
=====================================
ntpd/refclock_palisade.c
=====================================
--- a/ntpd/refclock_palisade.c
+++ b/ntpd/refclock_palisade.c
@@ -1062,8 +1062,9 @@ palisade_io (
case TSIP_PARSED_DLE_2:
if (*c == DLE) {
up->rpt_status = TSIP_PARSED_DATA;
- mb(up->rpt_cnt++) =
- *c;
+ /* prevent overrun - should never happen */
+ if (up->rpt_cnt < BMAX - 2)
+ mb(up->rpt_cnt++) = *c;
}
else if (*c == ETX)
up->rpt_status = TSIP_PARSED_FULL;
=====================================
tests/libntp/calendar.c
=====================================
--- a/tests/libntp/calendar.c
+++ b/tests/libntp/calendar.c
@@ -38,6 +38,7 @@ bool IsEqualCA(const struct calendar *expected, const struct calendar *actual) {
expected->second == actual->second) {
return true;
} else {
+ /* coverity[leaked_storage] */
printf("Expected: %s but was %s\n", CalendarToString(expected), CalendarToString(actual));
return false;
}
@@ -53,6 +54,7 @@ bool IsEqualISO(const struct isodate *expected, const struct isodate *actual) {
expected->second == actual->second) {
return true;
} else {
+ /* coverity[leaked_storage] */
printf("Expected: %s but was %s\n", CalendarToStringISO(expected), CalendarToStringISO(actual));
return false;
}
@@ -80,6 +82,7 @@ bool IsEqualDate(const struct calendar *expected, const struct calendar *actual)
expected->monthday == actual->monthday) {
return true;
} else {
+ /* coverity[leaked_storage] */
printf("Expected: %s but was %s\n", DateToString(expected), DateToString(actual));
return false;
}
@@ -92,6 +95,7 @@ bool IsEqualDateISO(const struct isodate *expected, const struct isodate *actual
expected->weekday == actual->weekday) {
return true;
} else {
+ /* coverity[leaked_storage] */
printf("Expected: %s but was %s\n", DateToStringISO(expected), DateToStringISO(actual));
return false;
}
=====================================
tests/libntp/caljulian.c
=====================================
--- a/tests/libntp/caljulian.c
+++ b/tests/libntp/caljulian.c
@@ -30,6 +30,7 @@ bool IsEqualC(const struct calendar *expected, const struct calendar *actual) {
expected->second == actual->second) {
return true;
} else {
+ /* coverity[leaked_storage] */
printf("expected: %s but was %s", CalendarToString(expected), CalendarToString(actual));
return false;
=====================================
tests/ntpdig/kod_file.c
=====================================
--- a/tests/ntpdig/kod_file.c
+++ b/tests/ntpdig/kod_file.c
@@ -54,6 +54,7 @@ TEST(kodFile, ReadCorrectFile) {
TEST_ASSERT_EQUAL_STRING("RSTR", res->type);
TEST_ASSERT_EQUAL_STRING("192.0.2.100", res->hostname);
TEST_ASSERT_EQUAL(0xfff, res->timestamp);
+ /* coverity[leaked_storage] */
}
TEST(kodFile, ReadFileWithBlankLines) {
@@ -80,6 +81,7 @@ TEST(kodFile, ReadFileWithBlankLines) {
TEST_ASSERT_EQUAL_STRING("DENY", res->type);
TEST_ASSERT_EQUAL_STRING("example.com", res->hostname);
TEST_ASSERT_EQUAL(0xabcd, res->timestamp);
+ /* coverity[leaked_storage] */
}
TEST(kodFile, WriteEmptyFile) {
=====================================
tests/ntpdig/packet_handling.c
=====================================
--- a/tests/ntpdig/packet_handling.c
+++ b/tests/ntpdig/packet_handling.c
@@ -239,6 +239,7 @@ TEST(packetHandling, HandleKodDemobilize) {
TEST_ASSERT_EQUAL(1, search_entry(HOSTNAME, &entry));
TEST_ASSERT_TRUE(memcmp(REASON, entry->type, 4) == 0);
+ /* coverity[leaked_storage] */
}
TEST(packetHandling, HandleKodRate) {
=====================================
tests/ntpdig/packet_processing.c
=====================================
--- a/tests/ntpdig/packet_processing.c
+++ b/tests/ntpdig/packet_processing.c
@@ -105,6 +105,7 @@ TEST(packetProcessing, TooShortExtensionFieldLength) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warray-bounds"
#endif
+ /* coverity[overrun-local] */
testpkt.exten[7] = htonl(3); // 3 bytes is too short.
#ifdef __clang__
#pragma clang diagnostic pop
=====================================
tests/ntpdig/utilities.c
=====================================
--- a/tests/ntpdig/utilities.c
+++ b/tests/ntpdig/utilities.c
@@ -20,6 +20,7 @@ const char * Version = "stub unit test Version string";
struct addrinfo CreateAddrinfo(sockaddr_u* sock) {
struct addrinfo a;
+ memset(&a, '\0', sizeof(struct addrinfo));
a.ai_family = sock->sa.sa_family;
a.ai_addrlen = SIZEOF_SOCKADDR(a.ai_family);
a.ai_addr = &sock->sa;
@@ -75,8 +76,11 @@ TEST(utilities, IPv4Address) {
sockaddr_u input = CreateSockaddr4(ADDR, 123);
struct addrinfo inputA = CreateAddrinfo(&input);
+ /* coverity[leaked_storage] */
TEST_ASSERT_EQUAL_STRING(ADDR, ss_to_str(&input));
+ /* coverity[leaked_storage] */
TEST_ASSERT_EQUAL_STRING(ADDR, addrinfo_to_str(&inputA));
+ /* coverity[leaked_storage] */
}
TEST(utilities, IPv6Address) {
@@ -93,10 +97,12 @@ TEST(utilities, IPv6Address) {
memset(&input, 0, sizeof(input));
input.sa6.sin6_family = AF_INET6;
input.sa6.sin6_addr = address;
+ /* coverity[leaked_storage] */
TEST_ASSERT_EQUAL_STRING(expected, ss_to_str(&input));
inputA = CreateAddrinfo(&input);
- TEST_ASSERT_EQUAL_STRING(expected, addrinfo_to_str(&inputA));
+ /* coverity[leaked_storage] */
+TEST_ASSERT_EQUAL_STRING(expected, addrinfo_to_str(&inputA));
}
TEST(utilities, SetLiVnMode1) {
=====================================
tests/unity/unity_fixture.c
=====================================
--- a/tests/unity/unity_fixture.c
+++ b/tests/unity/unity_fixture.c
@@ -284,7 +284,7 @@ typedef struct _PointerPair
} PointerPair;
enum {MAX_POINTERS=50};
-static PointerPair pointer_store[MAX_POINTERS];
+static PointerPair pointer_store[MAX_POINTERS+1];
static int pointer_index = 0;
void UnityPointer_Init(void)
@@ -295,12 +295,16 @@ void UnityPointer_Init(void)
void UnityPointer_Set(void ** pointer, void * newValue)
{
if (pointer_index >= MAX_POINTERS)
+ {
TEST_FAIL_MESSAGE("Too many pointers set");
-
- pointer_store[pointer_index].pointer = pointer;
- pointer_store[pointer_index].old_value = *pointer;
- *pointer = newValue;
- pointer_index++;
+ }
+ else
+ {
+ pointer_store[pointer_index].pointer = pointer;
+ pointer_store[pointer_index].old_value = *pointer;
+ *pointer = newValue;
+ pointer_index++;
+ }
}
void UnityPointer_UndoAllSets(void)
=====================================
util/bumpclock.c
=====================================
--- a/util/bumpclock.c
+++ b/util/bumpclock.c
@@ -25,6 +25,7 @@ int main(int argc, char *argv[]) {
er1 = errno;
set = was;
+ /* coverity[tainted_data] */
set.tv_usec += bump;
while (set.tv_usec >= 1000000 ) {
set.tv_usec -= 1000000;
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/41dbe2da23cb063024d4426817c2b18b7c0fc475
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151207/6c5e9d1c/attachment.html>
More information about the vc
mailing list