a699858
From 2eca7f5fa97a24997e4d8f900460ba43ae167e97 Mon Sep 17 00:00:00 2001
a699858
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
a699858
Date: Tue, 29 Jan 2019 18:07:44 +0100
a699858
Subject: [PATCH] Fallback to ASCII on output IDN conversion error
a699858
a699858
It is possible dig used ACE encoded name in locale, which does not
a699858
support converting it to unicode. Instead of fatal error, fallback to
a699858
ACE name on output.
a699858
a699858
(cherry picked from commit 7f4cb8f9584597fea16de6557124ac8b1bd47440)
a699858
a699858
Modify idna test to fallback to ACE
a699858
a699858
Test valid A-label on input would be displayed as A-label on output if
a699858
locale does not allow U-label.
a699858
a699858
(cherry picked from commit 4ce232f8605bdbe0594ebe5a71383c9d4e6f263b)
a699858
a699858
Emit warning on IDN output failure
a699858
a699858
Warning is emitted before any dig headers.
a699858
a699858
(cherry picked from commit 4b410038c531fbb902cd5fb83174eed1f06cb7d7)
a699858
---
a699858
 bin/dig/dighost.c              | 15 +++++++++++++--
a699858
 bin/tests/system/idna/tests.sh | 17 +++++++++++++++++
a699858
 2 files changed, 30 insertions(+), 2 deletions(-)
a699858
a699858
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
a699858
index bb8702c..d7cfc33 100644
a699858
--- a/bin/dig/dighost.c
a699858
+++ b/bin/dig/dighost.c
a699858
@@ -4860,9 +4860,20 @@ idn_ace_to_locale(const char *from, char *to, size_t tolen) {
a699858
 	 */
a699858
 	res = idn2_to_unicode_8zlz(utf8_src, &tmp_str, 0);
a699858
 	if (res != IDN2_OK) {
a699858
-		fatal("Cannot represent '%s' in the current locale (%s), "
a699858
-		      "use +noidnout or a different locale",
a699858
+		static bool warned = false;
a699858
+
a699858
+		res = idn2_to_ascii_8z(utf8_src, &tmp_str, 0);
a699858
+		if (res != IDN2_OK) {
a699858
+			fatal("Cannot represent '%s' "
a699858
+			      "in the current locale nor ascii (%s), "
a699858
+			      "use +noidnout or a different locale",
a699858
 		      from, idn2_strerror(res));
a699858
+		} else if (!warned) {
a699858
+			fprintf(stderr, ";; Warning: cannot represent '%s' "
a699858
+			      "in the current locale",
a699858
+			      tmp_str);
a699858
+			warned = true;
a699858
+		}
a699858
 	}
a699858
 
a699858
 	/*
a699858
diff --git a/bin/tests/system/idna/tests.sh b/bin/tests/system/idna/tests.sh
a699858
index 6637bf6..215a9d5 100644
a699858
--- a/bin/tests/system/idna/tests.sh
a699858
+++ b/bin/tests/system/idna/tests.sh
a699858
@@ -244,6 +244,23 @@ idna_enabled_test() {
a699858
     idna_test "$text" "+idnin +noidnout"   "xn--nxasmq6b.com" "xn--nxasmq6b.com."
a699858
     idna_test "$text" "+idnin +idnout"     "xn--nxasmq6b.com" "βόλοσ.com."
a699858
 
a699858
+    # Test of valid A-label in locale that cannot display it
a699858
+    #
a699858
+    # +noidnout: The string is sent as-is to the server and the returned qname
a699858
+    #            is displayed in the same form.
a699858
+    # +idnout:   The string is sent as-is to the server and the returned qname
a699858
+    #            is displayed as the corresponding A-label.
a699858
+    #
a699858
+    # The "+[no]idnout" flag has no effect in these cases.
a699858
+    text="Checking valid A-label in C locale"
a699858
+    label="xn--nxasmq6b.com"
a699858
+    LC_ALL=C idna_test "$text" ""                   "$label" "$label."
a699858
+    LC_ALL=C idna_test "$text" "+noidnin +noidnout" "$label" "$label."
a699858
+    LC_ALL=C idna_test "$text" "+noidnin +idnout"   "$label" "$label."
a699858
+    LC_ALL=C idna_test "$text" "+idnin +noidnout"   "$label" "$label."
a699858
+    LC_ALL=C idna_test "$text" "+idnin +idnout"     "$label" "$label."
a699858
+    LC_ALL=C idna_test "$text" "+noidnin +idnout"   "$label" "$label."
a699858
+
a699858
 
a699858
 
a699858
     # Tests of invalid A-labels
a699858
-- 
a699858
2.20.1
a699858