diff options
author | Christopher Zimmermann <chrisz@cvs.openbsd.org> | 2016-03-23 18:45:04 +0000 |
---|---|---|
committer | Christopher Zimmermann <chrisz@cvs.openbsd.org> | 2016-03-23 18:45:04 +0000 |
commit | 7f2d00bb1fb92cc08dc708cca83610db6d509566 (patch) | |
tree | e4551f4e4b239e96617661c1b092666b0c9d8b13 /lib/libc | |
parent | aa5b36d245eb6e6c6d8c0ef010bfa31e702ee74d (diff) |
Initialize _res_ext.nsaddr_list alongside _res.nsaddr_list.
Fallback to initialization with 0 when _res.nsaddr_list is to small to hold an
IPv6 address.
OK bluhm@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/asr/res_init.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/libc/asr/res_init.c b/lib/libc/asr/res_init.c index f6cb36ad40a..01a3023bf87 100644 --- a/lib/libc/asr/res_init.c +++ b/lib/libc/asr/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.8 2015/11/05 23:59:47 bluhm Exp $ */ +/* $OpenBSD: res_init.c,v 1.9 2016/03/23 18:45:03 chrisz Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -39,7 +39,7 @@ res_init(void) { _THREAD_PRIVATE_MUTEX(init); struct asr_ctx *ac; - int i, j; + int i; ac = _asr_use_resolver(NULL); @@ -57,15 +57,22 @@ res_init(void) if (_res.lookups[0] == '\0') strlcpy(_res.lookups, ac->ac_db, sizeof(_res.lookups)); - for (i = 0, j = 0; i < ac->ac_nscount && j < MAXNS; i++) { - if (ac->ac_ns[i]->sa_family != AF_INET || - ac->ac_ns[i]->sa_len > sizeof(_res.nsaddr_list[j])) - continue; - memcpy(&_res.nsaddr_list[j], ac->ac_ns[i], + for (i = 0; i < ac->ac_nscount && i < MAXNS; i++) { + /* + * No need to check for length since we copy to a + * struct sockaddr_storage with a size of 256 bytes + * and sa_len has only 8 bits. + */ + memcpy(&_res_ext.nsaddr_list[i], ac->ac_ns[i], ac->ac_ns[i]->sa_len); - j++; + if (ac->ac_ns[i]->sa_len <= sizeof(_res.nsaddr_list[i])) + memcpy(&_res.nsaddr_list[i], ac->ac_ns[i], + ac->ac_ns[i]->sa_len); + else + memset(&_res.nsaddr_list[i], 0, + sizeof(_res.nsaddr_list[i])); } - _res.nscount = j; + _res.nscount = i; _res.options |= RES_INIT; } _THREAD_PRIVATE_MUTEX_UNLOCK(init); |