From 38a63ed178c3f19f41ef0c3434b850a5cf50fd7e Mon Sep 17 00:00:00 2001 From: sthen Date: Wed, 15 Jan 2014 02:25:34 +0000 Subject: [PATCH] Initialise _res.nsaddr_list in res_init(), fixing some programs which depend on bind resolver internals. Note, the list will not be updated if resolv.conf is changed while the program runs unless the caller resets the RES_INIT flag. Approach suggested by otto@, original diff from Kapetanakis Giannis, fix suggested by tedu@ and dug up again by Riccardo Mottola. Looks ok to eric@. --- lib/libc/asr/res_init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libc/asr/res_init.c b/lib/libc/asr/res_init.c index c8958793b46..9fa0529baab 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.2 2013/05/27 17:31:01 eric Exp $ */ +/* $OpenBSD: res_init.c,v 1.3 2014/01/15 02:25:34 sthen Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -37,6 +37,7 @@ res_init(void) { _THREAD_PRIVATE_MUTEX(init); struct asr_ctx *ac; + int i; ac = asr_use_resolver(NULL); @@ -55,6 +56,10 @@ res_init(void) strlcpy(_res.lookups, ac->ac_db, sizeof(_res.lookups)); _res.nscount = ac->ac_nscount; + for (i = 0; i < ac->ac_nscount; i++) { + memcpy(&_res.nsaddr_list[i], ac->ac_ns[i], + ac->ac_ns[i]->sa_len); + } _res.options |= RES_INIT; } _THREAD_PRIVATE_MUTEX_UNLOCK(init); -- 2.20.1