diff options
Diffstat (limited to 'bin/dig/dighost.c')
-rw-r--r-- | bin/dig/dighost.c | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index d730c0ee5f34..df5a0c09f5fc 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2000-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.311.70.11 2009/11/10 17:27:13 each Exp $ */ +/* $Id: dighost.c,v 1.311.70.17 2010-12-09 01:12:54 marka Exp $ */ /*! \file * \note @@ -246,7 +246,7 @@ isc_result_t opentmpkey(isc_mem_t *mctx, const char *file, char **tempp, FILE **fp); isc_result_t removetmpkey(isc_mem_t *mctx, const char *file); void clean_trustedkey(void); -void insert_trustedkey(dst_key_t * key); +void insert_trustedkey(dst_key_t **key); #if DIG_SIGCHASE_BU isc_result_t getneededrr(dns_message_t *msg); void sigchase_bottom_up(dns_message_t *msg); @@ -970,7 +970,6 @@ setup_file_key(void) { keynametext, isc_result_totext(result)); goto failure; } - dstkey = NULL; failure: if (dstkey != NULL) dst_key_free(&dstkey); @@ -990,12 +989,21 @@ make_searchlist_entry(char *domain) { } static void +clear_searchlist(void) { + dig_searchlist_t *search; + while ((search = ISC_LIST_HEAD(search_list)) != NULL) { + ISC_LIST_UNLINK(search_list, search, link); + isc_mem_free(mctx, search); + } +} + +static void create_search_list(lwres_conf_t *confdata) { int i; dig_searchlist_t *search; debug("create_search_list()"); - ISC_LIST_INIT(search_list); + clear_searchlist(); for (i = 0; i < confdata->searchnxt; i++) { search = make_searchlist_entry(confdata->search[i]); @@ -1038,7 +1046,7 @@ setup_system(void) { else { /* No search list. Use the domain name if any */ if (lwconf->domainname != NULL) { domain = make_searchlist_entry(lwconf->domainname); - ISC_LIST_INITANDAPPEND(search_list, domain, link); + ISC_LIST_APPEND(search_list, domain, link); domain = NULL; } } @@ -1093,15 +1101,6 @@ setup_system(void) { } -static void -clear_searchlist(void) { - dig_searchlist_t *search; - while ((search = ISC_LIST_HEAD(search_list)) != NULL) { - ISC_LIST_UNLINK(search_list, search, link); - isc_mem_free(mctx, search); - } -} - /*% * Override the search list derived from resolv.conf by 'domain'. */ @@ -1201,14 +1200,15 @@ add_opt(dns_message_t *msg, isc_uint16_t udpsize, isc_uint16_t edns, if (dnssec) rdatalist->ttl |= DNS_MESSAGEEXTFLAG_DO; if (nsid) { - unsigned char data[4]; - isc_buffer_t buf; - - isc_buffer_init(&buf, data, sizeof(data)); - isc_buffer_putuint16(&buf, DNS_OPT_NSID); - isc_buffer_putuint16(&buf, 0); - rdata->data = data; - rdata->length = sizeof(data); + isc_buffer_t *b = NULL; + + result = isc_buffer_allocate(mctx, &b, 4); + check_result(result, "isc_buffer_allocate"); + isc_buffer_putuint16(b, DNS_OPT_NSID); + isc_buffer_putuint16(b, 0); + rdata->data = isc_buffer_base(b); + rdata->length = isc_buffer_usedlength(b); + dns_message_takebuffer(msg, &b); } else { rdata->data = NULL; rdata->length = 0; @@ -2218,6 +2218,15 @@ force_timeout(dig_lookup_t *l, dig_query_t *query) { isc_result_totext(ISC_R_NOMEMORY)); } isc_task_send(global_task, &event); + + /* + * The timer may have expired if, for example, get_address() takes + * long time and the timer was running on a different thread. + * We need to cancel the possible timeout event not to confuse + * ourselves due to the duplicate events. + */ + if (l->timer != NULL) + isc_timer_detach(&l->timer); } @@ -2241,7 +2250,7 @@ send_tcp_connect(dig_query_t *query) { query->waiting_connect = ISC_TRUE; query->lookup->current_query = query; result = get_address(query->servname, port, &query->sockaddr); - if (result == ISC_R_NOTFOUND) { + if (result != ISC_R_SUCCESS) { /* * This servname doesn't have an address. Try the next server * by triggering an immediate 'timeout' (we lie, but the effect @@ -2323,7 +2332,7 @@ send_udp(dig_query_t *query) { /* XXX Check the sense of this, need assertion? */ query->waiting_connect = ISC_FALSE; result = get_address(query->servname, port, &query->sockaddr); - if (result == ISC_R_NOTFOUND) { + if (result != ISC_R_SUCCESS) { /* This servname doesn't have an address. */ force_timeout(l, query); return; @@ -3858,14 +3867,15 @@ sigchase_scanname(dns_rdatatype_t type, dns_rdatatype_t covers, } void -insert_trustedkey(dst_key_t * key) +insert_trustedkey(dst_key_t **keyp) { - if (key == NULL) + if (*keyp == NULL) return; if (tk_list.nb_tk >= MAX_TRUSTED_KEY) return; - tk_list.key[tk_list.nb_tk++] = key; + tk_list.key[tk_list.nb_tk++] = *keyp; + *keyp = NULL; return; } @@ -4039,11 +4049,12 @@ get_trusted_key(isc_mem_t *mctx) fclose(fp); return (ISC_R_FAILURE); } - insert_trustedkey(key); #if 0 dst_key_tofile(key, DST_TYPE_PUBLIC,"/tmp"); #endif - key = NULL; + insert_trustedkey(&key); + if (key != NULL) + dst_key_free(&key); } return (ISC_R_SUCCESS); } |