[Git][NTPsec/ntpsec][master] 2 commits: Avoid Coverity warning.

Eric S. Raymond gitlab at mg.gitlab.com
Wed Oct 5 11:19:45 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
684938af by Eric S. Raymond at 2016-10-05T07:15:14-04:00
Avoid Coverity warning.

- - - - -
2e0e5cee by Eric S. Raymond at 2016-10-05T07:19:01-04:00
Fix a very old bug in peer_clear().

To randomize nextdate over the next poll interval we need (1 << peer->minpoll),
not peer->minpoll!  Not caught before because minpoll was not allowed
to go to 0 until recently.  Thank you, Coverity!

- - - - -


2 changed files:

- ntpd/ntp_intercept.c
- ntpd/ntp_proto.c


Changes:

=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -244,17 +244,20 @@ static void file_replay(const char *configfile, char *delimiter, char *tempfile)
     tfp = fopen(tempfile, "w");
     if (tfp == NULL)
 	replay_fail("can't copy %s\n", configfile);
-    for (;;) {
-	char *nextline = fgets(linebuf, sizeof(linebuf), stdin);
-
-	++lineno;
-	if (nextline == NULL)
-	    replay_fail("unexpected EOF\n");
-	if (strncmp(linebuf, delimiter, strlen(delimiter)) == 0)
-	    break;
-	fputs(linebuf, tfp);
+    else
+    {
+	for (;;) {
+	    char *nextline = fgets(linebuf, sizeof(linebuf), stdin);
+
+	    ++lineno;
+	    if (nextline == NULL)
+		replay_fail("unexpected EOF\n");
+	    if (strncmp(linebuf, delimiter, strlen(delimiter)) == 0)
+		break;
+	    fputs(linebuf, tfp);
+	}
+	fclose(tfp);
     }
-    fclose(tfp);
 }
 
 


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -1365,7 +1365,7 @@ peer_clear(
 	     * association ID fits the bill.
 	     */
 	    int pseudorandom = peer->associd ^ sock_hash(&peer->srcadr);
-	    peer->nextdate += pseudorandom % peer->minpoll;
+	    peer->nextdate += pseudorandom % (1 << peer->minpoll);
 	}
 #ifdef DEBUG
 	if (debug)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7ac2a7465583ae6a85a3c3e3f26f0739b8eb1e63...2e0e5ceea254473fad0e08e8a7bdc540743beafb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161005/9bb303f8/attachment.html>


More information about the vc mailing list