[Git][NTPsec/ntpsec][master] 2 commits: ntp_config: fix a real memory leak that coverity found.o

Gary E. Miller gitlab at mg.gitlab.com
Fri May 26 00:32:40 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
d5a4acb6 by Gary E. Miller at 2017-05-25T17:24:40-07:00
ntp_config: fix a real memory leak that coverity found.o

The memory was allocated at the top of a for loop and freed at the bottom
 of the loop, but the loop contained continue statements in the middle.

- - - - -
facf8d7c by Gary E. Miller at 2017-05-25T17:31:52-07:00
refclock_oncore: fix a coverity warning that could lead to random data.

The warning had been marked 'intentional'.

- - - - -


2 changed files:

- ntpd/ntp_config.c
- ntpd/refclock_oncore.c


Changes:

=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -1458,7 +1458,7 @@ config_access(
 	sockaddr_u		addr;
 	sockaddr_u		mask;
 	struct addrinfo		hints;
-	struct addrinfo *	ai_list;
+	struct addrinfo *	ai_list = NULL;
 	struct addrinfo *	pai;
 	int			rc;
 	bool			restrict_default;
@@ -1587,6 +1587,11 @@ config_access(
 	/* Configure the restrict options */
 	my_node = HEAD_PFIFO(ptree->restrict_opts);
 	for (; my_node != NULL; my_node = my_node->link) {
+		if (ai_list != NULL) {
+                        /* we do this here, to not need at every continue */
+			freeaddrinfo(ai_list);
+			ai_list = NULL;
+                }
 		/* Parse the flags */
 		flags = 0;
 		mflags = 0;
@@ -1696,7 +1701,6 @@ config_access(
 		}
 
 		ZERO_SOCK(&addr);
-		ai_list = NULL;
 		pai = NULL;
 		restrict_default = false;
 
@@ -1736,7 +1740,6 @@ config_access(
 				 * protocol machinery until after all
 				 * restrict hosts have been resolved.
 				 */
-				ai_list = NULL;
 				ZERO(hints);
 				hints.ai_protocol = IPPROTO_UDP;
 				hints.ai_socktype = SOCK_DGRAM;
@@ -1806,8 +1809,11 @@ config_access(
 			}
 		} while (pai != NULL);
 
-		if (ai_list != NULL)
-			freeaddrinfo(ai_list);
+	}
+	if (ai_list != NULL) {
+                /* coverity thinks this can happen, so just in case */
+		freeaddrinfo(ai_list);
+		ai_list = NULL;
 	}
 	/* coverity[leaked_storage] */
 }


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -1367,8 +1367,8 @@ oncore_read_config(
 			if (!strcmp(ca, "NO") || !strcmp(ca, "OFF"))    /* Yes/No, On/Off */
 				instance->traim_in = 0;
 		} else if (!strncmp(cc, "MASK", (size_t) 4)) {
-			/* coverity[unchecked_value] */
-			sscanf(ca, "%d", &mask);
+			if ( 1 != sscanf(ca, "%d", &mask) )
+                                mask = -1;
 			if (mask > -1 && mask < 90)
 				instance->Ag = mask;			/* Satellite mask angle */
 		} else if (!strncmp(cc,"PPSCONTROL",10)) {              /* pps control M12 only */



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/8eca35f62bce574b199f8e26ec6e0215394bbb16...facf8d7c163e58ff6015d0552fc3bda86a918bb0

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/8eca35f62bce574b199f8e26ec6e0215394bbb16...facf8d7c163e58ff6015d0552fc3bda86a918bb0
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170526/23918b68/attachment.html>


More information about the vc mailing list