urlapi: make two #defines instead of magic values/strings in code

Closes #22181
This commit is contained in:
Daniel Stenberg 2026-06-26 09:34:01 +02:00
parent cff59ddf4a
commit fdbc5beed3
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -53,6 +53,10 @@
/* scheme is not URL encoded, the longest libcurl supported ones are... */
#define MAX_SCHEME_LEN 40
#define MAX_ZONEID_LEN 16
/* characters not allowed in hostnames */
#define HOSTNAME_INVALID_CHARS " \r\n\t/:#?!@{}[]\\$\'\"^`*<>=;,+&()%|"
/*
* If USE_IPV6 is disabled, we still want to parse IPv6 addresses, so make
@ -425,13 +429,13 @@ UNITTEST CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname,
hlen = len;
if(hostname[len] == '%') {
/* this could now be '%[zone id]' */
char zoneid[16];
char zoneid[MAX_ZONEID_LEN];
int i = 0;
char *h = &hostname[len + 1];
/* pass '25' if present and is a URL encoded percent sign */
if(!strncmp(h, "25", 2) && h[2] && (h[2] != ']'))
h += 2;
while(*h && (*h != ']') && (i < 15))
while(*h && (*h != ']') && (i < (MAX_ZONEID_LEN - 1)))
zoneid[i++] = *h++;
if(!i || (']' != *h))
return CURLUE_BAD_IPV6;
@ -474,7 +478,7 @@ static CURLUcode hostname_check(struct Curl_URL *u, char *hostname,
return ipv6_parse(u, hostname, hlen);
else {
/* letters from the second string are not ok */
len = strcspn(hostname, " \r\n\t/:#?!@{}[]\\$\'\"^`*<>=;,+&()%|");
len = strcspn(hostname, HOSTNAME_INVALID_CHARS);
if(hlen != len)
/* hostname with bad content */
return CURLUE_BAD_HOSTNAME;