From: Florian Obser Subject: Re: Skip aliases that are not valid hostnames in gethostbyname(3). To: tech@openbsd.org Date: Sun, 21 Jun 2026 19:29:21 +0200 On 2026-04-11 18:05 +02, Florian Obser wrote: > Consider the following CNAME chain: > > chain7.narrans.de. 60 IN CNAME chain\007.tlakh.xyz. > chain\007.tlakh.xyz. 60 IN CNAME chain.sha256.net. > chain.sha256.net. 60 IN CNAME sha256.net. > sha256.net. 60 IN A 213.239.192.17 > > gethostbyname(3) would fail the query when it encounters > chain\007.tlakh.xyz. and tries to add it to h_aliases member of struct > hostent because it's not a valid hostname. This in turn would fail the > whole query. > > With this, resolution succeeds and we get an alias list of > "chain0.narrans.de chain.sha256.net". > > hostent_add_alias() can no longer fail, so make it void. > > Noticed by dgl while we were working on something else. > > OK? going through diffs that didn't make release. OK? diff --git lib/libc/asr/gethostnamadr_async.c lib/libc/asr/gethostnamadr_async.c index 1b0ab9d59e3..0b9a6ab0641 100644 --- lib/libc/asr/gethostnamadr_async.c +++ lib/libc/asr/gethostnamadr_async.c @@ -55,7 +55,7 @@ struct netent_ext { static int gethostnamadr_async_run(struct asr_query *, struct asr_result *); static struct hostent_ext *hostent_alloc(int); static int hostent_set_cname(struct hostent_ext *, const char *, int); -static int hostent_add_alias(struct hostent_ext *, const char *, int); +static void hostent_add_alias(struct hostent_ext *, const char *, int); static int hostent_add_addr(struct hostent_ext *, const void *, size_t); static struct hostent_ext *hostent_from_addr(int, const char *, const char *); static struct hostent_ext *hostent_file_match(FILE *, int, int, const char *, @@ -477,8 +477,7 @@ found: if (hostent_set_cname(h, tokens[1], 0) == -1) goto fail; for (i = 2; i < n; i ++) - if (hostent_add_alias(h, tokens[i], 0) == -1) - goto fail; + hostent_add_alias(h, tokens[i], 0); if (hostent_add_addr(h, addr, h->h.h_length) == -1) goto fail; return (h); @@ -517,8 +516,7 @@ hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen) case T_CNAME: if (reqtype == ASR_GETHOSTBYNAME) { - if (hostent_add_alias(h, rr.rr_dname, 1) == -1) - goto fail; + hostent_add_alias(h, rr.rr_dname, 1); } else { if (strcasecmp(rr.rr_dname, dname) == 0) strlcpy(dname, rr.rr.cname.cname, @@ -612,7 +610,7 @@ hostent_set_cname(struct hostent_ext *h, const char *name, int isdname) return (0); } -static int +static void hostent_add_alias(struct hostent_ext *h, const char *name, int isdname) { char buf[MAXDNAME]; @@ -622,24 +620,23 @@ hostent_add_alias(struct hostent_ext *h, const char *name, int isdname) if (h->aliases[i] == NULL) break; if (i == MAXALIASES) - return (0); + return; if (isdname) { _asr_strdname(name, buf, sizeof buf); buf[strlen(buf)-1] = '\0'; if (!res_hnok(buf)) - return (-1); + return; name = buf; } n = strlen(name) + 1; if (h->pos + n >= h->end) - return (0); + return; h->aliases[i] = h->pos; memmove(h->pos, name, n); h->pos += n; - return (0); } static int -- In my defence, I have been left unsupervised.