From 531bfbd61fd45e8361516a03aa71485f75d723f2 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 11 Dec 2022 13:52:48 -0800 Subject: [PATCH] Fix DNS resolution w/ commas in Windows Registry --- libc/dns/getntnameservers.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libc/dns/getntnameservers.c b/libc/dns/getntnameservers.c index 37c44ee23..f985a6c21 100644 --- a/libc/dns/getntnameservers.c +++ b/libc/dns/getntnameservers.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/arraylist.internal.h" #include "libc/calls/calls.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dns/dns.h" #include "libc/dns/resolvconf.h" +#include "libc/mem/arraylist.internal.h" #include "libc/nt/enum/keyaccess.h" #include "libc/nt/enum/reggetvalueflags.h" #include "libc/nt/registry.h" @@ -42,6 +42,7 @@ textwindows int GetNtNameServers(struct ResolvConf *resolv) { int rc; char value8[128]; int64_t hkInterfaces; + char *state, *addr, *tmp; struct sockaddr_in nameserver; char16_t value[128], uuid[64]; uint32_t i, keycount, valuebytes, uuidlen; @@ -75,8 +76,12 @@ textwindows int GetNtNameServers(struct ResolvConf *resolv) { ((valuebytes = sizeof(value)), &valuebytes)) && valuebytes > 2 * sizeof(char16_t)))) { tprecode16to8(value8, sizeof(value8), value); - if (inet_pton(AF_INET, value8, &nameserver.sin_addr.s_addr) == 1) { - if (append(&resolv->nameservers, &nameserver) != -1) ++rc; + tmp = value8; + while ((addr = strtok_r(tmp, ", ", &state))) { + if (inet_pton(AF_INET, addr, &nameserver.sin_addr.s_addr) == 1) { + if (append(&resolv->nameservers, &nameserver) != -1) ++rc; + } + tmp = NULL; } } }