From 9d5247875699abdfe130a06bbf62a1078d3f0cbf Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 31 Mar 2024 10:42:52 -0300 Subject: [PATCH] Terminate 'buf' properly The previous approach would provide inconsistent results. --- src/isinetaddr4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/isinetaddr4.c b/src/isinetaddr4.c index 95f5adc..0a5e092 100644 --- a/src/isinetaddr4.c +++ b/src/isinetaddr4.c @@ -18,20 +18,19 @@ isinetaddr4(const char *str) int digits = 0, octets = 1, buflen = 0; size_t len = (str == NULL ? 0 : strnlen(str, MAX_STRLEN)); - buf[MAX_BUFLEN] = '\0'; for (size_t i = 0; i < len; i++) { if (str[i] == SEP) { if (octets == MAX_OCTETS || buflen == 0) { return false; } else { buflen = 0; - bzero(buf, MAX_BUFLEN); } } else if (isdigit(str[i])) { if (buflen == MAX_BUFLEN) { return false; } else { buf[buflen++] = str[i]; + buf[buflen] = '\0'; digits++; if (!within_range(buf)) { return false;