[Git][NTPsec/ntpsec][master] 3 commits: interfaceiter: fix format casts.

Gary E. Miller gitlab at mg.gitlab.com
Wed Apr 12 22:08:09 UTC 2017


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


Commits:
c0a1e107 by Gary E. Miller at 2017-04-12T14:54:04-07:00
interfaceiter: fix format casts.

- - - - -
ef1d3792 by Gary E. Miller at 2017-04-12T15:03:24-07:00
dodecodenum(): return meaningfull error code, have tests use it.

- - - - -
d9f5e064 by Gary E. Miller at 2017-04-12T15:05:40-07:00
generic: fix implicit format sign changes.

- - - - -


6 changed files:

- include/ntp_stdlib.h
- libisc/interfaceiter.c
- libntp/decodenetnum.c
- ntpd/ntp_control.c
- ntpd/refclock_generic.c
- tests/libntp/decodenetnum.c


Changes:

=====================================
include/ntp_stdlib.h
=====================================
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -138,7 +138,7 @@ extern	bool	octtoint	(const char *, unsigned long *);
 extern	unsigned long	ranp2		(int);
 extern	const char *refid_str	(uint32_t, int);
 
-extern	bool	decodenetnum	(const char *, sockaddr_u *);
+extern	int	decodenetnum	(const char *, sockaddr_u *);
 
 extern	void	signal_no_reset (int, void (*func)(int));
 


=====================================
libisc/interfaceiter.c
=====================================
--- a/libisc/interfaceiter.c
+++ b/libisc/interfaceiter.c
@@ -203,7 +203,9 @@ linux_if_inet6_current(isc_interfaceiter_t *iter) {
 	}
 
 	res = sscanf(iter->entry, "%32[a-f0-9] %x %x %x %x %16s\n",
-		     address, &ifindex, &prefix, &scope, &flags, name);
+		     address, &ifindex, (unsigned int *)&prefix,
+                     (unsigned int *) &scope,
+                     (unsigned int *)&flags, name);
 	if (res != 6) {
 /*		isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
 			      ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,


=====================================
libntp/decodenetnum.c
=====================================
--- a/libntp/decodenetnum.c
+++ b/libntp/decodenetnum.c
@@ -26,8 +26,11 @@
  * [IPv6]:port
  *
  * The IP must be numeric but the port can be symbolic.
+ *
+ * return: 0 for success
+ *         negative numbers for error codes
  */
-bool
+int
 decodenetnum(
 	const char *num,
 	sockaddr_u *netnum
@@ -43,13 +46,13 @@ decodenetnum(
 	ZERO(*netnum);               /* don't return random data on fail */
         /* check num not NULL before using it */
 	if ( NULL == num) {
-                return false;
+                return -1;
         }
 	numlen = strlen(num);
 	/* Quickly reject empty or impossibly long inputs. */
 	if(numlen == 0 ||
 	   numlen > ((sizeof(ip) - 1) + (NI_MAXSERV - 1) + (3 /* "[]:" */))) {
-		return false;
+		return -2;
 	}
 
 	/* Is this a bracketed IPv6 address? */
@@ -70,7 +73,7 @@ decodenetnum(
 		}
 		else {
 			/* Anything else must be invalid. */
-			return false;
+			return -3;
 		}
 	}
 	/* No brackets. Searching backward, see if there's at least one
@@ -104,7 +107,7 @@ decodenetnum(
 	   whether the IP is short enough to possibly be valid and
 	   if so copy it into ip. */
 	if ((ip_end - ip_start + 1) > (int)sizeof(ip)) {
-		return false;
+		return -4;
 	} else {
 		memcpy(ip, ip_start, (size_t)(ip_end - ip_start));
 		ip[ip_end - ip_start] = '\0';
@@ -124,7 +127,7 @@ decodenetnum(
 	   Let getaddrinfo() perform all further validation. */
 	if(getaddrinfo(ip, port_start == NULL ? "ntp" : port_start,
 		       &hints, &ai) != 0) {
-		return false;
+		return -5;
 	}
 
 	NTP_INSIST(ai->ai_addrlen <= sizeof(*netnum));
@@ -132,5 +135,5 @@ decodenetnum(
 		memcpy(netnum, ai->ai_addr, ai->ai_addrlen);
 	}
 	freeaddrinfo(ai);
-	return true;
+	return 0;
 }


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -3464,7 +3464,7 @@ static void read_mru_list(
 			if (1 != sscanf(val, "%u", &maxlstint))
 				goto blooper;
 		} else if (!strcmp(laddr_text, v->text)) {
-			if (!decodenetnum(val, &laddr))
+			if (decodenetnum(val, &laddr))
 				goto blooper;
 			lcladr = getinterface(&laddr, 0);
 		} else if (!strcmp(recent_text, v->text)) {
@@ -3479,7 +3479,7 @@ static void read_mru_list(
 				priors++;
 		} else if (1 == sscanf(v->text, addr_fmt, &si) &&
 			   (size_t)si < COUNTOF(addr)) {
-			if (!decodenetnum(val, &addr[si]))
+			if (decodenetnum(val, &addr[si]))
 				goto blooper;
 			if (lfpuint(last[si]) && lfpfrac(last[si]) && si == priors)
 				priors++;


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -2761,7 +2761,9 @@ parse_start(
 
 	if (!PARSE_SETCS(parse, &tmp_ctl))
 	{
-		msyslog(LOG_ERR, "PARSE receiver #%d: parse_start: parse_setcs() FAILED.", unit);
+		msyslog(LOG_ERR,
+                    "PARSE receiver #%u: parse_start: parse_setcs() FAILED.",
+                    unit);
 		parse_shutdown(parse->peer->refclkunit, peer); /* let our cleaning staff do the work */
 		return false;			/* well, ok - special initialisation broke */
 	}
@@ -2771,7 +2773,9 @@ parse_start(
 
 	if (!PARSE_SETFMT(parse, &tmp_ctl))
 	{
-		msyslog(LOG_ERR, "PARSE receiver #%d: parse_start: parse_setfmt() FAILED.", unit);
+		msyslog(LOG_ERR,
+                    "PARSE receiver #%u: parse_start: parse_setfmt() FAILED.",
+                    unit);
 		parse_shutdown(parse->peer->refclkunit, peer); /* let our cleaning staff do the work */
 		return false;			/* well, ok - special initialisation broke */
 	}


=====================================
tests/libntp/decodenetnum.c
=====================================
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -15,7 +15,7 @@ TEST_TEAR_DOWN(decodenetnum) {}
 
 TEST(decodenetnum, IPv4AddressOnly) {
 	const char *str = "192.0.2.1";
-        bool ret;
+        int ret;
 	sockaddr_u actual;
 
 	sockaddr_u expected;
@@ -24,25 +24,27 @@ TEST(decodenetnum, IPv4AddressOnly) {
 	SET_PORT(&expected, NTP_PORT);
 
 	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(0, ret);
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
-	TEST_ASSERT_TRUE(ret);
 }
 
 TEST(decodenetnum, IPv4AddressWithPort) {
 	const char *str = "192.0.2.2:2000";
 	sockaddr_u actual;
+        int ret;
 
 	sockaddr_u expected;
 	SET_AF(&expected, AF_INET);
 	PSOCK_ADDR4(&expected)->s_addr = inet_addr("192.0.2.2");
 	SET_PORT(&expected, 2000);
 
-	TEST_ASSERT_TRUE(decodenetnum(str, &actual));
+	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(0, ret);
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
 }
 
 TEST(decodenetnum, IPv6AddressOnly) {
-        bool ret;
+        int ret;
 	const struct in6_addr address = {{{
 		0x20, 0x01, 0x0d, 0xb8,
         0x85, 0xa3, 0x08, 0xd3,
@@ -59,8 +61,8 @@ TEST(decodenetnum, IPv6AddressOnly) {
 	SET_PORT(&expected, NTP_PORT);
 
 	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(0, ret);
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
-	TEST_ASSERT_TRUE(ret);
 }
 
 TEST(decodenetnum, IPv6AddressWithPort) {
@@ -70,6 +72,7 @@ TEST(decodenetnum, IPv6AddressWithPort) {
         0x13, 0x19, 0x8a, 0x2e,
         0x03, 0x70, 0x73, 0x34
 	}}};
+        int ret;
 
 	const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
 	sockaddr_u actual;
@@ -79,15 +82,18 @@ TEST(decodenetnum, IPv6AddressWithPort) {
 	SET_SOCK_ADDR6(&expected, address);
 	SET_PORT(&expected, 3000);
 
-	TEST_ASSERT_TRUE(decodenetnum(str, &actual));
+	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(0, ret);
 	TEST_ASSERT_TRUE(IsEqualS(&expected, &actual));
 }
 
 TEST(decodenetnum, IllegalAddress) {
 	const char *str = "192.0.2.270:2000";
 	sockaddr_u actual;
+        int ret;
 
-	TEST_ASSERT_FALSE(decodenetnum(str, &actual));
+	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(-5, ret);
 }
 
 TEST(decodenetnum, IllegalCharInPort) {
@@ -96,13 +102,15 @@ TEST(decodenetnum, IllegalCharInPort) {
 	 */
 	const char *str = "192.0.2.1:a700";
 	sockaddr_u actual;
+        int ret;
 
 	sockaddr_u expected;
 	SET_AF(&expected, AF_INET);
 	PSOCK_ADDR4(&expected)->s_addr = inet_addr("192.0.2.1");
 	SET_PORT(&expected, NTP_PORT);
 
-	TEST_ASSERT_FALSE(decodenetnum(str, &actual));
+	ret = decodenetnum(str, &actual);
+	TEST_ASSERT_EQUAL_INT(-5, ret);
 	TEST_ASSERT_TRUE(IsDiffS(&expected, &actual));
 }
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/dfdf63a6f01aa67481c251e7c4cdde2e7d28b62d...d9f5e064bf240946abd0b7bd6727b57294aec21f

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/dfdf63a6f01aa67481c251e7c4cdde2e7d28b62d...d9f5e064bf240946abd0b7bd6727b57294aec21f
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/20170412/2df113d9/attachment.html>


More information about the vc mailing list