From 1c73d6aef5945ad713946bdcb7457f26508f0c23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 14 Dec 2020 11:50:10 +0100 Subject: [PATCH] lib/utils kr_straddr_subnet(): fix some error detection inet_pton() has slightly unexpected return values. Only one function was wrong; I don't count the unused kr_straddr_join(). --- lib/utils.c | 4 ++-- modules/hints/hints.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 6c1c91570..ea10f2925 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -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); } diff --git a/modules/hints/hints.c b/modules/hints/hints.c index cf85449c3..34edcc5de 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -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; -- 2.47.3