diff options
author | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-11-21 13:33:54 +0000 |
---|---|---|
committer | Martijn van Duren <martijn@cvs.openbsd.org> | 2021-11-21 13:33:54 +0000 |
commit | b4d6251b266f9a732692f4e73d373f9d8f6c6aa2 (patch) | |
tree | d6f2475cbaa1c7ddcb35ae6961e77e733ad2e9f9 | |
parent | 3bfeddb06c225d8db6d872f580a96373728aee38 (diff) |
getaddrinfo doesn't resolve numeric hostname in the !AI_NUMERICHOST case
if family in resolv.conf is not set to its specific family.
e.g. 0.0.0.0 will not resolve if family is set to "family inet6"
Fix this by first trying to resolve with AI_NUMERIC set and if EAI_NONAME
is returned (it's an actual hostname) retry with an empty ai_flags.
bug reported by and OK sthen@
-rw-r--r-- | usr.sbin/snmpd/parse.y | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index eaa334c2f3c..b1b3d5c9dd7 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.72 2021/10/25 11:21:32 martijn Exp $ */ +/* $OpenBSD: parse.y,v 1.73 2021/11/21 13:33:53 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -1600,7 +1600,16 @@ host(const char *s, const char *port, int type, struct sockaddr_storage *ss, bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = type; + /* + * Without AI_NUMERICHOST getaddrinfo might not resolve ip addresses + * for families not specified in the "family" statement in resolv.conf. + */ + hints.ai_flags = AI_NUMERICHOST; error = getaddrinfo(s, port, &hints, &res0); + if (error == EAI_NONAME) { + hints.ai_flags = 0; + error = getaddrinfo(s, port, &hints, &res0); + } if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME) return 0; if (error) { |