From 9baa5f9fe41c4bcc1241971d22332dff9ae9e739 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 25 Aug 2023 20:05:43 -0300 Subject: [PATCH] Treat "123.45.67.891" as invalid --- src/isinetaddr.c | 7 +++---- test/isinetaddr_test.c | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/isinetaddr.c b/src/isinetaddr.c index 473a3a5..05a75fd 100644 --- a/src/isinetaddr.c +++ b/src/isinetaddr.c @@ -4,8 +4,8 @@ #include #include -static -int inrange(char buf[4]) +static int +inrange(char buf[4]) { char *err; long r; @@ -20,7 +20,6 @@ isinetaddr(const char *str) char buf[4]; int i = 0, j = 0, k = 0; size_t len = (str == NULL ? 0 : strnlen(str, 16)); - for (size_t l = 0; l < len; l++) { if (str[l] == '.') { if (inrange(buf)) { @@ -43,6 +42,6 @@ isinetaddr(const char *str) return 0; } } - return j == 3 && i <= 12 ? 1 : 0; + return j == 3 && i <= 12 && inrange(buf); } diff --git a/test/isinetaddr_test.c b/test/isinetaddr_test.c index bfda3a1..9c60c83 100644 --- a/test/isinetaddr_test.c +++ b/test/isinetaddr_test.c @@ -7,10 +7,12 @@ const char *valid[] = { "192.168.1.1", "0.0.0.0", "255.255.255.255", - "123.45.67.89" + "123.45.67.89", + "123.45.67.255", }; const char *invalid[] = { + "123.45.67.891", "192.168.500.1", ".192.168.1.1", "192..168.1.1",