diff options
author | Rich Felker <dalias@aerifal.cx> | 2022-10-19 14:02:48 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2022-10-19 14:02:48 -0400 |
commit | 63402be229facae2d0de9c5943a6ed25246fd021 (patch) | |
tree | 217f28e942d5ed28add09710cf07a9a4b440543e /src | |
parent | 0a7b4323b0f2b944dbd47a813c0c6e6813e7fd67 (diff) | |
download | musl-63402be229facae2d0de9c5943a6ed25246fd021.tar.gz musl-63402be229facae2d0de9c5943a6ed25246fd021.tar.bz2 musl-63402be229facae2d0de9c5943a6ed25246fd021.tar.xz musl-63402be229facae2d0de9c5943a6ed25246fd021.zip |
clean up dns_parse_callback
the only functional change here should be that MAXADDRS is only
checked for RRs that provide address results, so that a CNAME which
appears after an excessive number of address RRs does not get ignored.
I'm not aware of any servers that order the RRs this way, and it may
even be forbidden to do so, but I prefer having the callback logic not
be order dependent.
other than that, the motivation for this change is that the A and AAAA
cases were mostly duplicate code that could be combined as a single
code path.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/lookup_name.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index be0c0bdd..5f6867cb 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -114,29 +114,29 @@ struct dpc_ctx { static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) { char tmp[256]; + int family; struct dpc_ctx *ctx = c; + if (rr == RR_CNAME) { + if (__dn_expand(packet, (const unsigned char *)packet + ABUF_SIZE, + data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp)) + strcpy(ctx->canon, tmp); + return 0; + } if (ctx->cnt >= MAXADDRS) return 0; + if (rr != ctx->rrtype) return 0; switch (rr) { case RR_A: - if (rr != ctx->rrtype) return 0; if (len != 4) return -1; - ctx->addrs[ctx->cnt].family = AF_INET; - ctx->addrs[ctx->cnt].scopeid = 0; - memcpy(ctx->addrs[ctx->cnt++].addr, data, 4); + family = AF_INET; break; case RR_AAAA: - if (rr != ctx->rrtype) return 0; if (len != 16) return -1; - ctx->addrs[ctx->cnt].family = AF_INET6; - ctx->addrs[ctx->cnt].scopeid = 0; - memcpy(ctx->addrs[ctx->cnt++].addr, data, 16); - break; - case RR_CNAME: - if (__dn_expand(packet, (const unsigned char *)packet + ABUF_SIZE, - data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp)) - strcpy(ctx->canon, tmp); + family = AF_INET6; break; } + ctx->addrs[ctx->cnt].family = family; + ctx->addrs[ctx->cnt].scopeid = 0; + memcpy(ctx->addrs[ctx->cnt++].addr, data, len); return 0; } |