[Git][NTPsec/ntpsec][master] 3 commits: oncore: fix leaked storage. Fixes a coverity warning.

Gary E. Miller gitlab at mg.gitlab.com
Thu May 25 23:05:53 UTC 2017


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


Commits:
b3a9f211 by Gary E. Miller at 2017-05-25T15:26:05-07:00
oncore: fix leaked storage.  Fixes a coverity warning.

- - - - -
566cd091 by Gary E. Miller at 2017-05-25T15:38:27-07:00
oncore: move a stat() closer to where result is used.

Because of a coverity low impact warning, but will not fix it.

- - - - -
64e8d23a by Gary E. Miller at 2017-05-25T16:04:22-07:00
refclock_generic: coverity had found a real problem, actually fix it.

The comment said the coverity warning was bogus.  Believe the code
instead of the comments.

- - - - -


2 changed files:

- ntpd/refclock_generic.c
- ntpd/refclock_oncore.c


Changes:

=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -1450,6 +1450,7 @@ static struct parse_clockinfo
 static int ncltypes = sizeof(parse_clockinfo) / sizeof(struct parse_clockinfo);
 
 #define CLK_REALTYPE(x) ((int)(((x)->ttl) & 0x7F))
+/* carefull, CLK_TYPE() in refclock_trimle.c is different */
 #define CLK_TYPE(x)	((CLK_REALTYPE(x) >= ncltypes) ? ~0 : CLK_REALTYPE(x))
 #define CLK_PPS(x)	(((x)->ttl) & 0x80)
 
@@ -4758,6 +4759,7 @@ trimbletsip_init(
 {
 #if defined(VEOL) || defined(VEOL2)
 	struct termios tio;		/* NEEDED FOR A LONG TIME ! */
+	u_int type;
 	/*
 	 * allocate local data area
 	 */
@@ -4783,9 +4785,9 @@ trimbletsip_init(
 	}
 	else
 	{
-		/* The macro value is actually unsigned */
-		/* coverity[negative_returns] */
-		if ((parse_clockinfo[CLK_TYPE(parse->peer)].cl_lflag & ICANON))
+		type = (u_int)CLK_TYPE(parse->peer);
+		if ( (type != (u_int)~0) &&
+                     (parse_clockinfo[type].cl_lflag & ICANON))
 		{
 #ifdef VEOL
 			tio.c_cc[VEOL]  = ETX;


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -661,20 +661,20 @@ oncore_start(
 		return false;		/* exit, no file, can't start driver */
 	}
 
-	if (stat(device2, &stat2)) {
-		stat2.st_dev = stat2.st_ino = (ino_t)-2;
-		oncore_log_f(instance, LOG_ERR, "Can't stat fd2 (%s) %d %m",
-			     device2, errno);
-	}
-
 	fd1 = refclock_open(device1, SPEED, LDISC_RAW);
 	if (fd1 <= 0) {
 		oncore_log_f(instance, LOG_ERR, "Can't open fd1 (%s)",
 			     device1);
-		/* coverity[leaked_storage] */
+		free(instance);
 		return false;		/* exit, can't open file, can't start driver */
 	}
 
+	if (stat(device2, &stat2)) {
+		stat2.st_dev = stat2.st_ino = (ino_t)-2;
+		oncore_log_f(instance, LOG_ERR, "Can't stat fd2 (%s) %d %m",
+			     device2, errno);
+	}
+
 	/* for LINUX the PPS device is the result of a line discipline.
 	   It seems simplest to let an external program create the appropriate
 	   /dev/pps<n> file, and only check (carefully) for its existence here
@@ -683,6 +683,7 @@ oncore_start(
 		fd2 = fd1;
 	else
 	{	/* different devices here */
+		/* coverity[toctou] */
 		if ((fd2=open(device2, O_RDWR, 0777)) < 0) {
 			oncore_log_f(instance, LOG_ERR,
 				     "Can't open fd2 (%s)", device2);
@@ -726,6 +727,7 @@ oncore_start(
 		return false;
 	}
 	pp->unitptr = instance;
+        /* can not trivially free instance now */
 
 #ifdef ENABLE_ONCORE_SHMEM
 	/*



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/24b6ec56ccdd626c2c7187775fb699b594db4c6e...64e8d23a3c746f01df516f003ed99d7084e430f1

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/24b6ec56ccdd626c2c7187775fb699b594db4c6e...64e8d23a3c746f01df516f003ed99d7084e430f1
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/20170525/dc29bbae/attachment.html>


More information about the vc mailing list