From ee772458970050904199cd317df9e29cd753f306 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 2 Nov 2016 09:03:57 +1100 Subject: [PATCH] 4501. [bug] Fix 'dig -4 -6'/'dig -6 -4' error handling. [RT #43259] --- CHANGES | 2 ++ bin/dig/dig.c | 25 ++++++++++++++++++++----- bin/dig/dighost.c | 24 +++++++++++++++++++++--- bin/dig/host.c | 31 ++++++++++++++++++------------- bin/dig/include/dig/dig.h | 5 ++++- bin/dig/nslookup.c | 7 +++++-- bin/tests/system/digdelv/tests.sh | 6 +++--- 7 files changed, 73 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index 6848849ab6..7c0efae48b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +4501. [bug] Fix 'dig -4 -6'/'dig -6 -4' error handling. [RT #43259] + 4500. [bug] Support modifier I64 in isc__print_printf. [RT #43526] 4499. [port] MacOSX: silence deprecated function warning diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 48ddb9e30d..88b563ff05 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -67,7 +67,7 @@ static char domainopt[DNS_NAME_MAXTEXT]; static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE, ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE, multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE, - onesoa = ISC_FALSE; + onesoa = ISC_FALSE, ipv4only = ISC_FALSE, ipv6only = ISC_FALSE; static isc_uint32_t splitwidth = 0xffffffff; /*% rrcomments are neither explicitly enabled nor disabled by default */ @@ -1540,11 +1540,22 @@ preparse_args(int argc, char **argv) { continue; option = &rv[0][1]; while (strpbrk(option, single_dash_opts) == &option[0]) { - if (option[0] == 'm') { + switch (option[0]) { + case 'm': memdebugging = ISC_TRUE; isc_mem_debugging = ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD; - return; + break; + case '4': + if (ipv6only) + fatal("only one of -4 and -6 allowed"); + ipv4only = ISC_TRUE; + break; + case '6': + if (ipv4only) + fatal("only one of -4 and -6 allowed"); + ipv6only = ISC_TRUE; + break; } option = &option[1]; } @@ -1906,13 +1917,17 @@ main(int argc, char **argv) { ISC_LIST_INIT(search_list); debug("main()"); - preparse_args(argc, argv); progname = argv[0]; + preparse_args(argc, argv); result = isc_app_start(); check_result(result, "isc_app_start"); setup_libs(); + setup_system(ipv4only, ipv6only); parse_args(ISC_FALSE, ISC_FALSE, argc, argv); - setup_system(); + if (keyfile[0] != 0) + setup_file_key(); + else if (keysecret[0] != 0) + setup_text_key(); if (domainopt[0] != '\0') { set_search_domain(domainopt); usesearch = ISC_TRUE; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 6b120bb9af..5239227340 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -934,7 +934,7 @@ requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { } -static void +void setup_text_key(void) { isc_result_t result; dns_name_t keyname; @@ -1121,7 +1121,7 @@ read_confkey(void) { return (result); } -static void +void setup_file_key(void) { isc_result_t result; dst_key_t *dstkey = NULL; @@ -1224,13 +1224,31 @@ create_search_list(lwres_conf_t *confdata) { * settings. */ void -setup_system(void) { +setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only) { dig_searchlist_t *domain = NULL; lwres_result_t lwresult; unsigned int lwresflags; debug("setup_system()"); + if (ipv4only) { + if (have_ipv4) { + isc_net_disableipv6(); + have_ipv6 = ISC_FALSE; + } else { + fatal("can't find IPv4 networking"); + } + } + + if (ipv6only) { + if (have_ipv6) { + isc_net_disableipv4(); + have_ipv4 = ISC_FALSE; + } else { + fatal("can't find IPv6 networking"); + } + } + lwresflags = LWRES_CONTEXT_SERVERMODE; if (have_ipv4) lwresflags |= LWRES_CONTEXT_USEIPV4; diff --git a/bin/dig/host.c b/bin/dig/host.c index 690ff54ef2..7c914bb257 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -59,6 +59,7 @@ static int seen_error = -1; static isc_boolean_t list_addresses = ISC_TRUE; static dns_rdatatype_t list_type = dns_rdatatype_a; static isc_boolean_t printed_server = ISC_FALSE; +static isc_boolean_t ipv4only = ISC_FALSE, ipv6only = ISC_FALSE; static const char *opcodetext[] = { "QUERY", @@ -628,8 +629,16 @@ pre_parse_args(int argc, char **argv) { isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; break; - case '4': break; - case '6': break; + case '4': + if (ipv6only) + fatal("only one of -4 and -6 allowed"); + ipv4only = ISC_TRUE; + break; + case '6': + if (ipv4only) + fatal("only one of -4 and -6 allowed"); + ipv6only = ISC_TRUE; + break; case 'a': break; case 'c': break; case 'd': break; @@ -823,18 +832,10 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { /* Handled by pre_parse_args(). */ break; case '4': - if (have_ipv4) { - isc_net_disableipv6(); - have_ipv6 = ISC_FALSE; - } else - fatal("can't find IPv4 networking"); + /* Handled by pre_parse_args(). */ break; case '6': - if (have_ipv6) { - isc_net_disableipv4(); - have_ipv4 = ISC_FALSE; - } else - fatal("can't find IPv6 networking"); + /* Handled by pre_parse_args(). */ break; case 's': lookup->servfail_stops = ISC_TRUE; @@ -894,8 +895,12 @@ main(int argc, char **argv) { result = isc_app_start(); check_result(result, "isc_app_start"); setup_libs(); + setup_system(ipv4only, ipv6only); parse_args(ISC_FALSE, argc, argv); - setup_system(); + if (keyfile[0] != 0) + setup_file_key(); + else if (keysecret[0] != 0) + setup_text_key(); result = isc_app_onrun(mctx, global_task, onrun_callback, NULL); check_result(result, "isc_app_onrun"); isc_app_run(); diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index e6535e7328..db3017d11b 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -331,7 +331,7 @@ void setup_libs(void); void -setup_system(void); +setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only); isc_result_t parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max, @@ -416,6 +416,9 @@ void chase_sig(dns_message_t *msg); #endif +void setup_file_key(void); +void setup_text_key(void); + ISC_LANG_ENDDECLS #endif diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index f5a496cde2..08ad1e1548 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -914,9 +914,12 @@ main(int argc, char **argv) { setup_libs(); progname = argv[0]; + setup_system(ISC_FALSE, ISC_FALSE); parse_args(argc, argv); - - setup_system(); + if (keyfile[0] != 0) + setup_file_key(); + else if (keysecret[0] != 0) + setup_text_key(); if (domainopt[0] != '\0') set_search_domain(domainopt); if (in_use) diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 9e6d016948..bca28767dd 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -344,9 +344,9 @@ if [ -n "${DELV}" -a -x "${DELV}" ] ; then test "${f:-0}" -eq 4 || ret=1 if [ $ret != 0 ]; then echo "I:failed"; fi status=`expr $status + $ret` - - echo "I:exit status: $status" - [ $status -eq 0 ] || exit 1 else echo "${DELV:-delv} is not available, so skipping these delv tests" fi + +echo "I:exit status: $status" +[ $status -eq 0 ] || exit 1