urlapi: return CURLUE_BAD_HOSTNAME if puny2idn encoding fails

And document it. Only return out of memory when it actually is a memory
problem.

Pointed-out-by: Jacob Mealey
Closes #11674
This commit is contained in:
Daniel Stenberg 2023-08-15 09:16:54 +02:00
parent 9ec764ee1f
commit a281057091
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 85 additions and 49 deletions

View file

@ -1545,9 +1545,10 @@ CURLUcode curl_url_get(const CURLU *u, CURLUPart what,
#ifndef USE_IDN
return CURLUE_LACKS_IDN;
#else
allochost = Curl_idn_decode(u->host);
if(!allochost)
return CURLUE_OUT_OF_MEMORY;
CURLcode result = Curl_idn_decode(u->host, &allochost);
if(result)
return (result == CURLE_OUT_OF_MEMORY) ?
CURLUE_OUT_OF_MEMORY : CURLUE_BAD_HOSTNAME;
#endif
}
}
@ -1556,9 +1557,11 @@ CURLUcode curl_url_get(const CURLU *u, CURLUPart what,
#ifndef USE_IDN
return CURLUE_LACKS_IDN;
#else
allochost = Curl_idn_encode(u->host);
if(!allochost)
return CURLUE_OUT_OF_MEMORY;
CURLcode result = Curl_idn_encode(u->host, &allochost);
if(result)
/* this is the most likely error */
return (result == CURLE_OUT_OF_MEMORY) ?
CURLUE_OUT_OF_MEMORY : CURLUE_BAD_HOSTNAME;
#endif
}
}
@ -1632,9 +1635,11 @@ CURLUcode curl_url_get(const CURLU *u, CURLUPart what,
#ifndef USE_IDN
return CURLUE_LACKS_IDN;
#else
char *allochost = Curl_idn_decode(*part);
if(!allochost)
return CURLUE_OUT_OF_MEMORY;
char *allochost;
CURLcode result = Curl_idn_decode(*part, &allochost);
if(result)
return (result == CURLE_OUT_OF_MEMORY) ?
CURLUE_OUT_OF_MEMORY : CURLUE_BAD_HOSTNAME;
free(*part);
*part = allochost;
#endif
@ -1645,9 +1650,11 @@ CURLUcode curl_url_get(const CURLU *u, CURLUPart what,
#ifndef USE_IDN
return CURLUE_LACKS_IDN;
#else
char *allochost = Curl_idn_encode(*part);
if(!allochost)
return CURLUE_OUT_OF_MEMORY;
char *allochost;
CURLcode result = Curl_idn_encode(*part, &allochost);
if(result)
return (result == CURLE_OUT_OF_MEMORY) ?
CURLUE_OUT_OF_MEMORY : CURLUE_BAD_HOSTNAME;
free(*part);
*part = allochost;
#endif