Fix DNS resolution w/ commas in Windows Registry

This commit is contained in:
Justine Tunney 2022-12-11 13:52:48 -08:00
parent cd0b12ed1a
commit 531bfbd61f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/mem/arraylist.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dns/dns.h" #include "libc/dns/dns.h"
#include "libc/dns/resolvconf.h" #include "libc/dns/resolvconf.h"
#include "libc/mem/arraylist.internal.h"
#include "libc/nt/enum/keyaccess.h" #include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/reggetvalueflags.h" #include "libc/nt/enum/reggetvalueflags.h"
#include "libc/nt/registry.h" #include "libc/nt/registry.h"
@ -42,6 +42,7 @@ textwindows int GetNtNameServers(struct ResolvConf *resolv) {
int rc; int rc;
char value8[128]; char value8[128];
int64_t hkInterfaces; int64_t hkInterfaces;
char *state, *addr, *tmp;
struct sockaddr_in nameserver; struct sockaddr_in nameserver;
char16_t value[128], uuid[64]; char16_t value[128], uuid[64];
uint32_t i, keycount, valuebytes, uuidlen; uint32_t i, keycount, valuebytes, uuidlen;
@ -75,8 +76,12 @@ textwindows int GetNtNameServers(struct ResolvConf *resolv) {
((valuebytes = sizeof(value)), &valuebytes)) && ((valuebytes = sizeof(value)), &valuebytes)) &&
valuebytes > 2 * sizeof(char16_t)))) { valuebytes > 2 * sizeof(char16_t)))) {
tprecode16to8(value8, sizeof(value8), value); tprecode16to8(value8, sizeof(value8), value);
if (inet_pton(AF_INET, value8, &nameserver.sin_addr.s_addr) == 1) { tmp = value8;
if (append(&resolv->nameservers, &nameserver) != -1) ++rc; 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;
} }
} }
} }