Blame SOURCES/bind-9.5-libidn2.patch

bc5dde
diff -up bind-9.5.0b1/bin/dig/dighost.c.libidn2 bind-9.5.0b1/bin/dig/dighost.c
bc5dde
--- bind-9.5.0b1/bin/dig/dighost.c.libidn2	2007-12-10 13:12:26.000000000 +0100
bc5dde
+++ bind-9.5.0b1/bin/dig/dighost.c	2007-12-10 14:21:09.000000000 +0100
bc5dde
@@ -153,7 +153,7 @@ int  idnoptions	= 0;
bc5dde
 #endif
bc5dde
 
bc5dde
 #ifdef WITH_LIBIDN
bc5dde
-static isc_result_t	libidn_locale_to_utf8 (const char* from, char **to);
bc5dde
+static isc_result_t	libidn_locale_to_utf8 (const char* from, char *to);
bc5dde
 static isc_result_t	libidn_utf8_to_ascii (const char* from, char *to);
bc5dde
 static isc_result_t	output_filter (isc_buffer_t *buffer,
bc5dde
 				       unsigned int used_org,
bc5dde
@@ -1764,17 +1764,13 @@ setup_lookup(dig_lookup_t *lookup) {
bc5dde
 	char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
bc5dde
 #endif
bc5dde
 #ifdef WITH_LIBIDN
bc5dde
-	char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
bc5dde
+	char utf8_str[MXNAME], utf8_name[MXNAME], ascii_name[MXNAME];
bc5dde
 #endif
bc5dde
 
bc5dde
-#ifdef WITH_IDN
bc5dde
+#if defined (WITH_IDN) || defined (WITH_LIBIDN)
bc5dde
 	result = dns_name_settotextfilter(output_filter);
bc5dde
 	check_result(result, "dns_name_settotextfilter");
bc5dde
 #endif
bc5dde
-#ifdef WITH_LIBIDN
bc5dde
-	result = dns_name_settotextfilter (output_filter);
bc5dde
-	check_result(result, "dns_name_settotextfilter");
bc5dde
-#endif
bc5dde
 	REQUIRE(lookup != NULL);
bc5dde
 	INSIST(!free_now);
bc5dde
 
bc5dde
@@ -1812,15 +1808,13 @@ setup_lookup(dig_lookup_t *lookup) {
bc5dde
 			    utf8_textname, sizeof(utf8_textname));
bc5dde
 	idn_check_result(mr, "convert textname to UTF-8");
bc5dde
 #elif defined (WITH_LIBIDN)
bc5dde
-	result = libidn_locale_to_utf8 (lookup->textname, &utf8_str);
bc5dde
-	check_result (result, "converting textname to UTF-8");
bc5dde
+	result = libidn_locale_to_utf8 (lookup->textname, utf8_str);
bc5dde
+	check_result (result, "convert textname to UTF-8");
bc5dde
 	len = strlen (utf8_str);
bc5dde
-	if (len < MXNAME) {
bc5dde
+	if (len < MXNAME)
bc5dde
 		(void) strcpy (utf8_name, utf8_str);
bc5dde
-	} else {
bc5dde
+	else
bc5dde
 		fatal ("Too long name");
bc5dde
-	}
bc5dde
-	isc_mem_free (mctx, utf8_str);
bc5dde
 #endif
bc5dde
 
bc5dde
 	/*
bc5dde
@@ -1833,24 +1827,11 @@ setup_lookup(dig_lookup_t *lookup) {
bc5dde
 	if (lookup->new_search) {
bc5dde
 #ifdef WITH_IDN
bc5dde
 		if ((count_dots(utf8_textname) >= ndots) || !usesearch) {
bc5dde
-			lookup->origin = NULL; /* Force abs lookup */
bc5dde
-			lookup->done_as_is = ISC_TRUE;
bc5dde
-			lookup->need_search = usesearch;
bc5dde
-		} else if (lookup->origin == NULL && usesearch) {
bc5dde
-			lookup->origin = ISC_LIST_HEAD(search_list);
bc5dde
-			lookup->need_search = ISC_FALSE;
bc5dde
-		}
bc5dde
 #elif defined (WITH_LIBIDN)
bc5dde
 		if ((count_dots(utf8_name) >= ndots) || !usesearch) {
bc5dde
-			lookup->origin = NULL; /* Force abs lookup */
bc5dde
-			lookup->done_as_is = ISC_TRUE;
bc5dde
-			lookup->need_search = usesearch;
bc5dde
-		} else if (lookup->origin == NULL && usesearch) {
bc5dde
-			lookup->origin = ISC_LIST_HEAD(search_list);
bc5dde
-			lookup->need_search = ISC_FALSE;
bc5dde
-		}
bc5dde
 #else
bc5dde
 		if ((count_dots(lookup->textname) >= ndots) || !usesearch) {
bc5dde
+#endif
bc5dde
 			lookup->origin = NULL; /* Force abs lookup */
bc5dde
 			lookup->done_as_is = ISC_TRUE;
bc5dde
 			lookup->need_search = usesearch;
bc5dde
@@ -1858,7 +1839,6 @@ setup_lookup(dig_lookup_t *lookup) {
bc5dde
 			lookup->origin = ISC_LIST_HEAD(search_list);
bc5dde
 			lookup->need_search = ISC_FALSE;
bc5dde
 		}
bc5dde
-#endif
bc5dde
 	}
bc5dde
 
bc5dde
 #ifdef WITH_IDN
bc5dde
@@ -1877,15 +1857,12 @@ setup_lookup(dig_lookup_t *lookup) {
bc5dde
 	idn_check_result(mr, "convert UTF-8 textname to IDN encoding");
bc5dde
 #elif defined (WITH_LIBIDN)
bc5dde
 	if (lookup->origin != NULL) {
bc5dde
-		result = libidn_locale_to_utf8 (lookup->origin->origin, &utf8_str);
bc5dde
+		result = libidn_locale_to_utf8 (lookup->origin->origin, utf8_str);
bc5dde
 		check_result (result, "convert origin to UTF-8");
bc5dde
-		if (len + strlen (utf8_str) + 1 < MXNAME) {
bc5dde
-			utf8_name[len++] = '.';
bc5dde
+		if (len + strlen (utf8_str) < MXNAME)
bc5dde
 			(void) strcpy (utf8_name + len, utf8_str);
bc5dde
-		} else {
bc5dde
+		else
bc5dde
 			fatal ("Too long name + origin");
bc5dde
-		}
bc5dde
-		isc_mem_free (mctx, utf8_str);
bc5dde
 	}
bc5dde
 
bc5dde
 	result = libidn_utf8_to_ascii (utf8_name, ascii_name);
bc5dde
@@ -3600,76 +3577,85 @@ idn_check_result(idn_result_t r, const c
bc5dde
 }
bc5dde
 #endif /* WITH_IDN */
bc5dde
 #ifdef WITH_LIBIDN
bc5dde
-/* If stringprep_locale_to_utf8 fails simple copy string */
bc5dde
 static isc_result_t
bc5dde
-libidn_locale_to_utf8 (const char *from, char **to) {
bc5dde
+libidn_locale_to_utf8 (const char *from, char *to) {
bc5dde
 	char *utf8_str;
bc5dde
 
bc5dde
+	debug ("libidn_locale_to_utf8");
bc5dde
 	utf8_str = stringprep_locale_to_utf8 (from);
bc5dde
-	if (utf8_str == NULL) {
bc5dde
-		*to = isc_mem_allocate (mctx, strlen (from) + 1);
bc5dde
-		if (*to == NULL)
bc5dde
-			return (ISC_R_NOMEMORY);
bc5dde
-		(void) strcpy (*to, from);
bc5dde
-	} else {
bc5dde
-		*to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
bc5dde
-		if (*to == NULL)
bc5dde
-			return (ISC_R_NOMEMORY);
bc5dde
-		(void) strcpy (*to, utf8_str);
bc5dde
+	if (utf8_str != NULL) {
bc5dde
+		(void) strcpy (to, utf8_str);
bc5dde
 		free (utf8_str);
bc5dde
+		return ISC_R_SUCCESS;
bc5dde
 	}
bc5dde
-	return (ISC_R_SUCCESS);
bc5dde
+
bc5dde
+	debug ("libidn_locale_to_utf8: failure");
bc5dde
+	return ISC_R_FAILURE;
bc5dde
 }
bc5dde
 static isc_result_t
bc5dde
 libidn_utf8_to_ascii (const char *from, char *to) {
bc5dde
 	char *ascii;
bc5dde
+	int iresult;
bc5dde
 
bc5dde
-	if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
bc5dde
-		return (ISC_R_FAILURE);
bc5dde
+	debug ("libidn_utf8_to_ascii");
bc5dde
+	iresult = idna_to_ascii_8z (from, &ascii, 0);
bc5dde
+	if (iresult != IDNA_SUCCESS) {
bc5dde
+		debug ("idna_to_ascii_8z: %s", idna_strerror (iresult));
bc5dde
+		return ISC_R_FAILURE;
bc5dde
+	}
bc5dde
 
bc5dde
 	(void) strcpy (to, ascii);
bc5dde
 	free (ascii);
bc5dde
-	return (ISC_R_SUCCESS);
bc5dde
+	return ISC_R_SUCCESS;
bc5dde
 }
bc5dde
-/* based on idnkit's code*/
bc5dde
+
bc5dde
 static isc_result_t
bc5dde
 output_filter (isc_buffer_t *buffer, unsigned int used_org,
bc5dde
 	       isc_boolean_t absolute) {
bc5dde
+
bc5dde
 	char tmp1[MXNAME], *tmp2;
bc5dde
         size_t fromlen, tolen;
bc5dde
         isc_boolean_t end_with_dot;
bc5dde
+	int iresult;
bc5dde
+
bc5dde
+	debug ("output_filter");
bc5dde
 
bc5dde
-        fromlen = isc_buffer_usedlength(buffer) - used_org;
bc5dde
+        fromlen = isc_buffer_usedlength (buffer) - used_org;
bc5dde
 	if (fromlen >= MXNAME)
bc5dde
-		return (ISC_R_SUCCESS);
bc5dde
-        memcpy(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen);
bc5dde
+		return ISC_R_SUCCESS;
bc5dde
+        memcpy (tmp1, (char *) isc_buffer_base (buffer) + used_org, fromlen);
bc5dde
         end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE;
bc5dde
         if (absolute && !end_with_dot) {
bc5dde
                 fromlen++;
bc5dde
 		if (fromlen >= MXNAME)
bc5dde
-			return (ISC_R_SUCCESS);
bc5dde
+			return ISC_R_SUCCESS;
bc5dde
                 tmp1[fromlen - 1] = '.';
bc5dde
         }
bc5dde
         tmp1[fromlen] = '\0';
bc5dde
 
bc5dde
-	if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
bc5dde
-		return (ISC_R_SUCCESS);
bc5dde
+	iresult = idna_to_unicode_8z8z (tmp1, &tmp2, 0);
bc5dde
+	if (iresult != IDNA_SUCCESS) {
bc5dde
+		debug ("output_filter: %s", idna_strerror (iresult));
bc5dde
+		return ISC_R_SUCCESS;
bc5dde
+	}
bc5dde
 
bc5dde
 	(void) strcpy (tmp1, tmp2);
bc5dde
 	free (tmp2);
bc5dde
 
bc5dde
-        tolen = strlen(tmp1);
bc5dde
+        tolen = strlen (tmp1);
bc5dde
         if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
bc5dde
                 tolen--;
bc5dde
 
bc5dde
-        if (isc_buffer_length(buffer) < used_org + tolen)
bc5dde
-                return (ISC_R_NOSPACE);
bc5dde
+        if (isc_buffer_length (buffer) < used_org + tolen)
bc5dde
+                return ISC_R_NOSPACE;
bc5dde
+
bc5dde
+	debug ("%s", tmp1);
bc5dde
 
bc5dde
-        isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org);
bc5dde
-        memcpy(isc_buffer_used(buffer), tmp1, tolen);
bc5dde
-        isc_buffer_add(buffer, tolen);
bc5dde
+        isc_buffer_subtract (buffer, isc_buffer_usedlength (buffer) - used_org);
bc5dde
+        memcpy (isc_buffer_used (buffer), tmp1, tolen);
bc5dde
+        isc_buffer_add (buffer, tolen);
bc5dde
 
bc5dde
-        return (ISC_R_SUCCESS);
bc5dde
+        return ISC_R_SUCCESS;
bc5dde
 }
bc5dde
 #endif /* WITH_LIBIDN*/
bc5dde