[Git][NTPsec/ntpsec][master] 2 commits: decodenetnum(): return more error codes.

Gary E. Miller gitlab at mg.gitlab.com
Thu Apr 13 18:20:56 UTC 2017


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


Commits:
280cf6db by Gary E. Miller at 2017-04-13T11:10:53-07:00
decodenetnum(): return more error codes.

Adjust tests to match.

- - - - -
c3e3769f by Gary E. Miller at 2017-04-13T11:20:07-07:00
tests/leapsec: stop mising bools and ints

- - - - -


3 changed files:

- libntp/decodenetnum.c
- tests/libntp/decodenetnum.c
- tests/ntpd/leapsec.c


Changes:

=====================================
libntp/decodenetnum.c
=====================================
--- a/libntp/decodenetnum.c
+++ b/libntp/decodenetnum.c
@@ -40,19 +40,20 @@ decodenetnum(
 	const char *ip_start, *ip_end, *port_start, *temp;
 	size_t numlen;
 	bool have_brackets;
+        int retcode = 0;
 
 	char ip[INET6_ADDRSTRLEN];
 
 	ZERO(*netnum);               /* don't return random data on fail */
         /* check num not NULL before using it */
 	if ( NULL == num) {
-                return -1;
+                return -4001;
         }
 	numlen = strlen(num);
 	/* Quickly reject empty or impossibly long inputs. */
 	if(numlen == 0 ||
 	   numlen > ((sizeof(ip) - 1) + (NI_MAXSERV - 1) + (3 /* "[]:" */))) {
-		return -2;
+		return -4002;
 	}
 
 	/* Is this a bracketed IPv6 address? */
@@ -73,7 +74,7 @@ decodenetnum(
 		}
 		else {
 			/* Anything else must be invalid. */
-			return -3;
+			return -4003;
 		}
 	}
 	/* No brackets. Searching backward, see if there's at least one
@@ -107,7 +108,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 -4;
+		return -4004;
 	} else {
 		memcpy(ip, ip_start, (size_t)(ip_end - ip_start));
 		ip[ip_end - ip_start] = '\0';
@@ -125,9 +126,10 @@ decodenetnum(
 	   either the IP address or the port is well-formed, but at
 	   least they're unambiguously delimited from each other.
 	   Let getaddrinfo() perform all further validation. */
-	if(getaddrinfo(ip, port_start == NULL ? "ntp" : port_start,
-		       &hints, &ai) != 0) {
-		return -5;
+	retcode = getaddrinfo(ip, port_start == NULL ? "ntp" : port_start,
+		       &hints, &ai);
+	if(retcode) {
+		return retcode;
 	}
 
 	NTP_INSIST(ai->ai_addrlen <= sizeof(*netnum));


=====================================
tests/libntp/decodenetnum.c
=====================================
--- a/tests/libntp/decodenetnum.c
+++ b/tests/libntp/decodenetnum.c
@@ -93,7 +93,7 @@ TEST(decodenetnum, IllegalAddress) {
         int ret;
 
 	ret = decodenetnum(str, &actual);
-	TEST_ASSERT_EQUAL_INT(-5, ret);
+	TEST_ASSERT_NOT_EQUAL(0, ret);
 }
 
 TEST(decodenetnum, IllegalCharInPort) {
@@ -110,7 +110,7 @@ TEST(decodenetnum, IllegalCharInPort) {
 	SET_PORT(&expected, NTP_PORT);
 
 	ret = decodenetnum(str, &actual);
-	TEST_ASSERT_EQUAL_INT(-5, ret);
+	TEST_ASSERT_NOT_EQUAL(0, ret);
 	TEST_ASSERT_TRUE(IsDiffS(&expected, &actual));
 }
 


=====================================
tests/ntpd/leapsec.c
=====================================
--- a/tests/ntpd/leapsec.c
+++ b/tests/ntpd/leapsec.c
@@ -711,7 +711,7 @@ TEST(leapsec, ls2009seqInsDumb) {
 
 	rc = setup_load_table(leap1);
 	TEST_ASSERT_TRUE(rc);
-	TEST_ASSERT_EQUAL(0, leapsec_electric(-1));
+	TEST_ASSERT_FALSE(leapsec_electric(-1));
 
 	rc = leapsec_query(&qr, lsec2009 - 60*SECSPERDAY);
 	TEST_ASSERT_FALSE(rc);
@@ -802,7 +802,7 @@ TEST(leapsec, ls2009seqDelDumb) {
 
 	rc = setup_load_table(leap3);
 	TEST_ASSERT_TRUE(rc);
-	TEST_ASSERT_EQUAL(0, leapsec_electric(-1));
+	TEST_ASSERT_FALSE(leapsec_electric(-1));
 
 	rc = leapsec_query(&qr, lsec2009 - 60*SECSPERDAY);
 	TEST_ASSERT_FALSE(rc);
@@ -887,7 +887,7 @@ TEST(leapsec, ls2012seqInsDumb) {
 
 	rc = setup_load_table(leap1);
 	TEST_ASSERT_TRUE(rc);
-	TEST_ASSERT_EQUAL(0, leapsec_electric(-1));
+	TEST_ASSERT_FALSE(leapsec_electric(-1));
 
 	rc = leapsec_query(&qr, lsec2012 - 60*SECSPERDAY);
 	TEST_ASSERT_FALSE(rc);
@@ -937,7 +937,7 @@ TEST(leapsec, lsEmptyTableDumb) {
 	const uint32_t t0   = lsec2012 - 10;
 	const uint32_t tE   = lsec2012 + 10;
 
-	TEST_ASSERT_EQUAL(0, leapsec_electric(-1));
+	TEST_ASSERT_FALSE(leapsec_electric(-1));
 
 	for (t = t0; t != tE; ++t) {
 		rc = leapsec_query(&qr, t);
@@ -955,7 +955,7 @@ TEST(leapsec, lsEmptyTableElectric) {
 	time_t       t;
 
 	leapsec_electric(electric_on);
-	TEST_ASSERT_EQUAL(electric_on, leapsec_electric(electric_query));
+	TEST_ASSERT(electric_on == leapsec_electric(electric_query));
 
 	const time_t   t0 = lsec2012 - 10;
 	const time_t   tE = lsec2012 + 10;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f8efefbbc0dd7f15f400a45f4fb02ed06491d1be...c3e3769f92cb14b55ff2679668796d7dfee9e612

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f8efefbbc0dd7f15f400a45f4fb02ed06491d1be...c3e3769f92cb14b55ff2679668796d7dfee9e612
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/20170413/3898ece1/attachment.html>


More information about the vc mailing list