]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
idn: make Curl_idnconvert_hostname() use Curl_idn_decode()
authorDaniel Stenberg <daniel@haxx.se>
Sat, 30 Mar 2024 21:56:48 +0000 (22:56 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 31 Mar 2024 09:02:44 +0000 (11:02 +0200)
In the name of less code duplication

Closes #13236

lib/idn.c
lib/idn.h

index 81a177f8cf2957cf2b5a5c316aad713925b61caf..3890b0b06b1cb7b7f7d18d1f1cd1835b72b47967 100644 (file)
--- a/lib/idn.c
+++ b/lib/idn.c
@@ -246,11 +246,7 @@ CURLcode Curl_idn_encode(const char *puny, char **output)
  */
 void Curl_free_idnconverted_hostname(struct hostname *host)
 {
-  if(host->encalloc) {
-    /* must be freed with idn2_free() if allocated by libidn */
-    Curl_idn_free(host->encalloc);
-    host->encalloc = NULL;
-  }
+  Curl_safefree(host->encalloc);
 }
 
 #endif /* USE_IDN */
@@ -267,20 +263,11 @@ CURLcode Curl_idnconvert_hostname(struct hostname *host)
   /* Check name for non-ASCII and convert hostname if we can */
   if(!Curl_is_ASCII_name(host->name)) {
     char *decoded;
-    CURLcode result = idn_decode(host->name, &decoded);
-    if(!result) {
-      if(!*decoded) {
-        /* zero length is a bad host name */
-        Curl_idn_free(decoded);
-        return CURLE_URL_MALFORMAT;
-      }
-      /* successful */
-      host->encalloc = decoded;
-      /* change the name pointer to point to the encoded hostname */
-      host->name = host->encalloc;
-    }
-    else
+    CURLcode result = Curl_idn_decode(host->name, &decoded);
+    if(result)
       return result;
+    /* successful */
+    host->name = host->encalloc = decoded;
   }
 #endif
   return CURLE_OK;
index 74bbcaf4980d041a861a838c8ee1a62e36fe0521..e75124ef9f66182abf977091496f4c8c8203057e 100644 (file)
--- a/lib/idn.h
+++ b/lib/idn.h
@@ -31,11 +31,6 @@ CURLcode Curl_idnconvert_hostname(struct hostname *host);
 void Curl_free_idnconverted_hostname(struct hostname *host);
 CURLcode Curl_idn_decode(const char *input, char **output);
 CURLcode Curl_idn_encode(const char *input, char **output);
-#ifdef USE_LIBIDN2
-#define Curl_idn_free(x) idn2_free(x)
-#else
-#define Curl_idn_free(x) free(x)
-#endif
 
 #else
 #define Curl_free_idnconverted_hostname(x)