]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/utils kr_straddr_subnet(): fix some error detection
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 14 Dec 2020 10:50:10 +0000 (11:50 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 14 Dec 2020 10:54:18 +0000 (11:54 +0100)
inet_pton() has slightly unexpected return values.
Only one function was wrong; I don't count the unused kr_straddr_join().

lib/utils.c
modules/hints/hints.c

index 6c1c9157027479873cdf4bd7e1a3e52c53f29cfc..ea10f2925a62b13be95a09d30e9966829b707ad7 100644 (file)
@@ -536,7 +536,7 @@ int kr_straddr_subnet(void *dst, const char *addr)
        }
        /* Parse address */
        int ret = inet_pton(family, addr_str, dst);
-       if (ret < 0) {
+       if (ret != 1) {
                return kr_error(EILSEQ);
        }
 
@@ -577,7 +577,7 @@ int kr_straddr_join(const char *addr, uint16_t port, char *buf, size_t *buflen)
 
        struct sockaddr_storage ss;
        int family = kr_straddr_family(addr);
-       if (family == kr_error(EINVAL) || !inet_pton(family, addr, &ss)) {
+       if (family == kr_error(EINVAL) || inet_pton(family, addr, &ss) != 1) {
                return kr_error(EINVAL);
        }
 
index cf85449c3725ae541427c0c603a41922abf5b642..34edcc5deeed0152541780c9d9af63556452a08d 100644 (file)
@@ -175,7 +175,7 @@ static int parse_addr_str(union inaddr *sa, const char *addr)
        memset(sa, 0, sizeof(*sa));
        sa->ip.sa_family = family;
        char *addr_bytes = (/*const*/char *)kr_inaddr(&sa->ip);
-       if (inet_pton(family, addr, addr_bytes) < 1) {
+       if (inet_pton(family, addr, addr_bytes) != 1) {
                return kr_error(EILSEQ);
        }
        return 0;