From e12dc1faa24322ea9da31b72c9f33a48a4d3a440 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Sat, 12 Sep 2020 13:23:52 -0700 Subject: [PATCH] dig: setup IDN whenever printing a message because dig now uses the netmgr, printing of response messages happens in a different thread than setup. the IDN output filtering procedure, which set using dns_name_settotextfilter(), is stored as thread-local data, and so if it's set during setup, it won't be accessible when printing. we now set it immediately before printing, in the same thread, and clear it immedately afterward. --- bin/dig/dig.c | 5 +++++ bin/dig/dighost.c | 27 ++++++++++++++------------- bin/dig/dighost.h | 16 +++++++++++----- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 3dac5aa28b..692ea5ccac 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -552,6 +552,8 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg, UNUSED(msgbuf); + dig_idnsetup(query->lookup, true); + styleflags |= DNS_STYLEFLAG_REL_OWNER; if (yaml) { msg->indent.string = " "; @@ -912,6 +914,9 @@ repopulate_buffer: if (style != NULL) { dns_master_styledestroy(&style, mctx); } + + dig_idnsetup(query->lookup, false); + return (result); } diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index c3e428fb0e..525bf53dc8 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -2117,10 +2117,6 @@ setup_lookup(dig_lookup_t *lookup) { #ifdef HAVE_LIBIDN2 char idn_origin[MXNAME], idn_textname[MXNAME]; - - result = dns_name_settotextfilter(lookup->idnout ? idn_output_filter - : NULL); - check_result(result, "dns_name_settotextfilter"); #endif /* HAVE_LIBIDN2 */ INSIST(!free_now); @@ -4234,10 +4230,6 @@ cancel_all(void) { */ void destroy_libs(void) { -#ifdef HAVE_LIBIDN2 - isc_result_t result; -#endif /* HAVE_LIBIDN2 */ - if (keep != NULL) { isc_nmhandle_detach(&keep); } @@ -4275,11 +4267,6 @@ destroy_libs(void) { clear_searchlist(); -#ifdef HAVE_LIBIDN2 - result = dns_name_settotextfilter(NULL); - check_result(result, "dns_name_settotextfilter"); -#endif /* HAVE_LIBIDN2 */ - if (commctx != NULL) { debug("freeing commctx"); isc_mempool_destroy(&commctx); @@ -4476,3 +4463,17 @@ idn_ace_to_locale(const char *src, char **dst) { *dst = local_src; } #endif /* HAVE_LIBIDN2 */ + +void +dig_idnsetup(dig_lookup_t *lookup, bool active) { +#ifdef HAVE_LIBIDN2 + isc_result_t result; + result = dns_name_settotextfilter( + (active && lookup->idnout) ? idn_output_filter : NULL); + check_result(result, "dns_name_settotextfilter"); +#else + UNUSED(lookup); + UNUSED(active); + return; +#endif /* HAVE_LIBIDN2 */ +} diff --git a/bin/dig/dighost.h b/bin/dig/dighost.h index f9bbaf92d3..2e3278ae06 100644 --- a/bin/dig/dighost.h +++ b/bin/dig/dighost.h @@ -388,32 +388,38 @@ setup_text_key(void); * Routines exported from dig.c for use by dig for iOS */ -/*%< +/*% * Call once only to set up libraries, parse global * parameters and initial command line query parameters */ void dig_setup(int argc, char **argv); -/*%< +/*% * Call to supply new parameters for the next lookup */ void dig_query_setup(bool, bool, int argc, char **argv); -/*%< +/*% * set the main application event cycle running */ void dig_startup(void); -/*%< +/*% * Initiates the next lookup cycle */ void dig_query_start(void); -/*%< +/*% + * Activate/deactivate IDN filtering of output. + */ +void +dig_idnsetup(dig_lookup_t *lookup, bool active); + +/*% * Cleans up the application */ void