From 2d9d97e66e9e29de128c21cb676b9661df20dede Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Wed, 17 May 2023 21:39:42 +0200 Subject: [PATCH] ifconfig: improve error checking for carp peer6 getaddrinfo() returns 0 if it succeeded, but it's not guaranteed to return 1 on error. Check for success rather than for one specific error. Without this fix commands such as `ifconfig bnxt1 inet6 add vhid 1 peer6 2001:db8::1/64` would segfault ifconfig. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/ifconfig/carp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c index aab5f2985328..2a2d8ce407ab 100644 --- a/sbin/ifconfig/carp.c +++ b/sbin/ifconfig/carp.c @@ -237,7 +237,7 @@ setcarp_peer6(const char *val, int d, int s, const struct afswtch *afp) hints.ai_family = AF_INET6; hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(val, NULL, &hints, &res) == 1) + if (getaddrinfo(val, NULL, &hints, &res) != 0) errx(1, "Invalid IPv6 address %s", val); memcpy(&carp_addr6, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,