From 6f4de018afc682c52ba33c8f60d974412f7b9dad Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 10 Sep 2021 00:02:11 +0100 Subject: [PATCH] Revert "Skip ascii-only names IDN processing" This reverts commit 9cb7f8a655596013dfdea2136ee6539be9905bd5. --- src/util.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/util.c b/src/util.c index 9925194..1425764 100644 --- a/src/util.c +++ b/src/util.c @@ -115,8 +115,7 @@ u64 rand64(void) return (u64)out[outleft+1] + (((u64)out[outleft]) << 32); } -/* returns 1 if name is OK and ascii printable - * returns 2 if name should be processed by IDN */ +/* returns 2 if names is OK but contains one or more underscores */ static int check_name(char *in) { /* remove trailing . @@ -124,7 +123,6 @@ static int check_name(char *in) size_t dotgap = 0, l = strlen(in); char c; int nowhite = 0; - int r = 1; int hasuscore = 0; if (l == 0 || l > MAXDNAME) return 0; @@ -144,30 +142,22 @@ static int check_name(char *in) else if (isascii((unsigned char)c) && iscntrl((unsigned char)c)) /* iscntrl only gives expected results for ascii */ return 0; - else if (!isascii((unsigned char)c)) #if !defined(HAVE_IDN) && !defined(HAVE_LIBIDN2) + else if (!isascii((unsigned char)c)) return 0; -#else - r = 2; #endif else if (c != ' ') { nowhite = 1; -#if defined(HAVE_LIBIDN2) && (!defined(IDN2_VERSION_NUMBER) || IDN2_VERSION_NUMBER < 0x02000003) - /* older libidn2 strips underscores, so don't do IDN processing - if the name has an underscore */ if (c == '_') hasuscore = 1; -#else - (void)hasuscore; -#endif } } if (!nowhite) return 0; - return (hasuscore) ? 1 : r; + return hasuscore ? 2 : 1; } /* Hostnames have a more limited valid charset than domain names @@ -214,8 +204,12 @@ char *canonicalise(char *in, int *nomem) if (!(rc = check_name(in))) return NULL; +#if defined(HAVE_LIBIDN2) && (!defined(IDN2_VERSION_NUMBER) || IDN2_VERSION_NUMBER < 0x02000003) + /* older libidn2 strips underscores, so don't do IDN processing + if the name has an underscore (check_name() returned 2) */ + if (rc != 2) +#endif #if defined(HAVE_IDN) || defined(HAVE_LIBIDN2) - if (rc == 2) { # ifdef HAVE_LIBIDN2 rc = idn2_to_ascii_lz(in, &ret, IDN2_NONTRANSITIONAL); @@ -240,14 +234,12 @@ char *canonicalise(char *in, int *nomem) return ret; } -#else - (void)rc; #endif if ((ret = whine_malloc(strlen(in)+1))) strcpy(ret, in); else if (nomem) - *nomem = 1; + *nomem = 1; return ret; }