BUG/MINOR: dns: allow 63 char in hostname

hostname were limited to 62 char, which is not RFC1035 compliant;
- the parsing loop should stop when above max label char
- fix len label test where d[i] was wrongly used
- simplify the whole function to avoid using two extra char* variable

this should fix github issue #387

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
Reviewed-by: Tim Duesterhus <tim@bastelstu.be>
Acked-by: Baptiste <bedis9@gmail.com>
This commit is contained in:
William Dauchy 2020-01-26 19:52:34 +01:00 committed by Willy Tarreau
parent bd8bf67102
commit aecd5dcac2

View File

@ -1470,7 +1470,6 @@ int dns_str_to_dn_label(const char *str, int str_len, char *dn, int dn_len)
*/ */
int dns_hostname_validation(const char *string, char **err) int dns_hostname_validation(const char *string, char **err)
{ {
const char *c, *d;
int i; int i;
if (strlen(string) > DNS_MAX_NAME_SIZE) { if (strlen(string) > DNS_MAX_NAME_SIZE) {
@ -1479,36 +1478,32 @@ int dns_hostname_validation(const char *string, char **err)
return 0; return 0;
} }
c = string; while (*string) {
while (*c) {
d = c;
i = 0; i = 0;
while (*d != '.' && *d && i <= DNS_MAX_LABEL_SIZE) { while (*string && *string != '.' && i < DNS_MAX_LABEL_SIZE) {
i++; if (!(*string == '-' || *string == '_' ||
if (!((*d == '-') || (*d == '_') || (*string >= 'a' && *string <= 'z') ||
((*d >= 'a') && (*d <= 'z')) || (*string >= 'A' && *string <= 'Z') ||
((*d >= 'A') && (*d <= 'Z')) || (*string >= '0' && *string <= '9'))) {
((*d >= '0') && (*d <= '9')))) {
if (err) if (err)
*err = DNS_INVALID_CHARACTER; *err = DNS_INVALID_CHARACTER;
return 0; return 0;
} }
d++; i++;
string++;
} }
if ((i >= DNS_MAX_LABEL_SIZE) && (d[i] != '.')) { if (!(*string))
break;
if (*string != '.' && i >= DNS_MAX_LABEL_SIZE) {
if (err) if (err)
*err = DNS_LABEL_TOO_LONG; *err = DNS_LABEL_TOO_LONG;
return 0; return 0;
} }
if (*d == '\0') string++;
goto out;
c = ++d;
} }
out:
return 1; return 1;
} }