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