From bf269b652f40a59de325b654e024c17daaea2eb3 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 14 Aug 2017 20:46:07 +0200 Subject: [PATCH 3/4] ping6: simplified IDNA usage The function was converting from locale to UTF-8, performing some check and then converting to IDNA form. Convert instead directly to IDNA from locale format and perform the check afterwards. Signed-off-by: Nikos Mavrogiannopoulos (cherry picked from commit 8f7b6908746f0eef3bb0f8fdf8b2a8c82ae9afe2) Resolves: #1449149 --- ping6_common.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/ping6_common.c b/ping6_common.c index 498e590..bf4777d 100644 --- a/ping6_common.c +++ b/ping6_common.c @@ -435,14 +435,14 @@ static int niquery_option_subject_addr_handler(int index, const char *arg) return 0; } -static int niquery_option_subject_name_handler(int index, const char *arg) +static int niquery_option_subject_name_handler(int index, const char *name) { #ifdef USE_CRYPTO static char nigroup_buf[INET6_ADDRSTRLEN + 1 + IFNAMSIZ]; unsigned char *dnptrs[2], **dpp, **lastdnptr; int n; int i; - char *name, *p; + char *p; char *canonname = NULL, *idn = NULL; unsigned char *buf = NULL; size_t namelen; @@ -458,18 +458,19 @@ static int niquery_option_subject_name_handler(int index, const char *arg) return -1; #ifdef USE_IDN - name = stringprep_locale_to_utf8(arg); - if (!name) { - fprintf(stderr, "ping6: IDN support failed.\n"); + rc = idna_to_ascii_lz(name, &idn, 0); + if (rc) { + fprintf(stderr, "ping6: IDN encoding error: %s\n", + idna_strerror(rc)); exit(2); } #else - name = strdup(arg); - if (!name) + idn = strdup(name); + if (!idn) goto oomexit; #endif - p = strchr(name, SCOPE_DELIMITER); + p = strchr(idn, SCOPE_DELIMITER); if (p) { *p = '\0'; if (strlen(p + 1) >= IFNAMSIZ) { @@ -478,19 +479,6 @@ static int niquery_option_subject_name_handler(int index, const char *arg) } } -#ifdef USE_IDN - rc = idna_to_ascii_8z(name, &idn, 0); - if (rc) { - fprintf(stderr, "ping6: IDN encoding error: %s\n", - idna_strerror(rc)); - exit(2); - } -#else - idn = strdup(name); - if (!idn) - goto oomexit; -#endif - namelen = strlen(idn); canonname = malloc(namelen + 1); if (!canonname) @@ -552,7 +540,6 @@ static int niquery_option_subject_name_handler(int index, const char *arg) free(canonname); free(idn); - free(name); return 0; oomexit: @@ -561,7 +548,6 @@ errexit: free(buf); free(canonname); free(idn); - free(name); exit(1); #else fprintf(stderr, "ping6: function not available; crypto disabled\n"); -- 2.13.6