[Git][NTPsec/ntpsec][master] Coverity cleanup. Plugs at least one slow memory leak in async DNS.
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Jan 25 10:11:52 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
815e48a2 by Eric S. Raymond at 2016-01-25T05:10:43-05:00
Coverity cleanup. Plugs at least one slow memory leak in async DNS.
- - - - -
9 changed files:
- libntp/ntp_intres.c
- libparse/ieee754io.c
- ntpd/keyword-gen.c
- ntpd/ntp_config.c
- ntpd/ntp_intercept.c
- ntpd/refclock_jupiter.c
- ntpfrob/pps-api.c
- ntpq/ntpq-subs.c
- tests/ntpdig/utilities.c
Changes:
=====================================
libntp/ntp_intres.c
=====================================
--- a/libntp/ntp_intres.c
+++ b/libntp/ntp_intres.c
@@ -414,6 +414,8 @@ blocking_getaddrinfo(
return -1;
}
+ /* FIXME: might be a real resource leak, not a Coverity false positive */
+ /* coverity[leaked_storage] */
return 0;
}
=====================================
libparse/ieee754io.c
=====================================
--- a/libparse/ieee754io.c
+++ b/libparse/ieee754io.c
@@ -349,6 +349,7 @@ fetch_ieee754(
*/
lfpp->l_ui = mantissa_high << (32 - frac_offset);
lfpp->l_ui |= (mantissa_low >> frac_offset) & ((1 << (32 - frac_offset)) - 1);
+ /* coverity[large_shift] */
lfpp->l_uf = (mantissa_low & ((1 << frac_offset) - 1)) << (32 - frac_offset);
}
}
@@ -490,6 +491,7 @@ put_ieee754(
mantissa_high = (outlfp.l_ui << (mbits - msb)) & ((1 << (mbits - 32)) - 1);
mantissa_high |= outlfp.l_uf >> (32 - (mbits - msb));
mantissa_low = (outlfp.l_ui & ((1 << (msb - mbits)) - 1)) << (32 - (msb - mbits));
+ /* coverity[shift_negative] */
mantissa_low |= outlfp.l_uf >> (msb - mbits);
}
else
=====================================
ntpd/keyword-gen.c
=====================================
--- a/ntpd/keyword-gen.c
+++ b/ntpd/keyword-gen.c
@@ -398,6 +398,7 @@ generate_fsm(void)
}
if (sst[i].finishes_token) {
+ /* coverity[leaked_storage] */
snprintf(token_id_comment,
sizeof(token_id_comment), "%5d %-17s",
i, symbname(sst[i].finishes_token));
@@ -549,6 +550,7 @@ create_scan_states(
sst[my_state].followedby = (char)followedby;
if (sst[token].finishes_token != (u_short)token) {
+ /* coverity[leaked_storage] */
fprintf(stderr,
"fatal, sst[%d] not reserved for %s.\n",
token, symbname(token));
@@ -637,6 +639,7 @@ generate_token_text(void)
}
if (i > 0)
printf(",");
+ /* coverity[leaked_storage] */
printf("\n\t/* %-5d %5d %20s */\t\"%s\"",
id - lowest_id, id, symbname(id),
ntp_keywords[i].key);
=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -2550,6 +2550,7 @@ config_access(
if (ai_list != NULL)
freeaddrinfo(ai_list);
}
+ /* coverity[leaked_storage] */
}
#endif /* !SIM */
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -191,6 +191,7 @@ void intercept_argparse(int *argc, char ***argv)
if (was_space)
*cp = '\0';
}
+ /* coverity[leaked_storage] */
}
}
@@ -298,6 +299,7 @@ bool intercept_getaddrinfo(char *hname, sockaddr_u *peeraddrp)
memset(peeraddrp, '\0', sizeof(*peeraddrp));
octets = min(sizeof(*peeraddrp), res->ai_addrlen);
memcpy(peeraddrp, res->ai_addr, octets);
+ freeaddrinfo(res);
return true;
}
}
@@ -504,8 +506,8 @@ int intercept_adjtime(const struct timeval *ntv, struct timeval *otv)
/* avoid compiler warnings due to time_t having an unexpected length */
rntv.tv_sec = nsec;
rntv.tv_usec = nusec;
- rntv.tv_sec = osec;
- rntv.tv_usec = ousec;
+ rotv.tv_sec = osec;
+ rotv.tv_usec = ousec;
if (ntv->tv_sec != rntv.tv_sec
|| ntv->tv_usec != rntv.tv_usec
|| otv->tv_sec != rotv.tv_sec
=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -831,6 +831,7 @@ jupiter_parse_gpos(struct instance *instance, u_short *sp)
instance->gpos_gweek = jg->gweek;
instance->gpos_sweek = DS2UI(jg->sweek);
+ /* coverity[tainted_data] */
while(instance->gpos_sweek >= WEEKSECS) {
instance->gpos_sweek -= WEEKSECS;
++instance->gpos_gweek;
=====================================
ntpfrob/pps-api.c
=====================================
--- a/ntpfrob/pps-api.c
+++ b/ntpfrob/pps-api.c
@@ -88,7 +88,7 @@ void ppscheck(char *device)
if (i < 0)
err(1, "time_pps_getcap");
- pp.mode = PPS_CAPTUREASSERT | PPS_ECHOASSERT;
+ /* pp.mode = PPS_CAPTUREASSERT | PPS_ECHOASSERT; */
pp.mode = PPS_CAPTUREBOTH;
/* pp.mode = PPS_CAPTUREASSERT; */
=====================================
ntpq/ntpq-subs.c
=====================================
--- a/ntpq/ntpq-subs.c
+++ b/ntpq/ntpq-subs.c
@@ -1866,6 +1866,7 @@ doprintpeers(
return true;
}
else
+ /* coverity[leaked_storage] */
return true;
}
=====================================
tests/ntpdig/utilities.c
=====================================
--- a/tests/ntpdig/utilities.c
+++ b/tests/ntpdig/utilities.c
@@ -54,10 +54,16 @@ void FinishDebugTest(const char *expected,
fp_a = fopen(actual, "rb");
fp_e = fopen(expected, "rb");
- CompareFileContent(fp_e, fp_a);
-
- fclose(fp_a);
- fclose(fp_e);
+ if (fp_a != NULL && fp_e != NULL)
+ CompareFileContent(fp_e, fp_a);
+ else
+ fprintf(stderr,
+ "FinishDebugTest: file pointer unexpectedly null.\n");
+
+ if (fp_a)
+ fclose(fp_a);
+ if (fp_e)
+ fclose(fp_e);
free((void*) expected);
free((void*) actual);
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/815e48a2daa01fbf272398d21be759476c7137ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160125/4d63f651/attachment.html>
More information about the vc
mailing list