From 24c3bfb681463a2b6d7de7efdc9a2e279440541f Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 25 Aug 2023 18:25:20 -0300 Subject: [PATCH] Handle 'str' being NULL --- src/isinetaddr.c | 3 ++- test/isinetaddr_test.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/isinetaddr.c b/src/isinetaddr.c index 87146af..125096e 100644 --- a/src/isinetaddr.c +++ b/src/isinetaddr.c @@ -19,8 +19,9 @@ isinetaddr(const char *str) { char buf[4]; int i = 0, j = 0, k = 0; - size_t len = strnlen(str, 16); + size_t len; + len = str == NULL ? 0 : strnlen(str, 16); for(size_t l = 0; l < len; l++) { if (str[l] == '.') { if (inrange(buf)) { diff --git a/test/isinetaddr_test.c b/test/isinetaddr_test.c index 325a78c..1ee63de 100644 --- a/test/isinetaddr_test.c +++ b/test/isinetaddr_test.c @@ -18,7 +18,8 @@ const char *invalid[] = { "192.168.1.1..", "192.168.1.1a", "555555555555555555555555555555555", - "" + "", + NULL }; int