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>
(cherry picked from commit aecd5dcac2cd4cd87639596980c449f887b2ca26)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit f0b2e0b463c350439772070b575b1992c68c68ca)
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/dns.c b/src/dns.c
index e1e6b90..e8801f2 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -1225,7 +1225,6 @@
*/
int dns_hostname_validation(const char *string, char **err)
{
- const char *c, *d;
int i;
if (strlen(string) > DNS_MAX_NAME_SIZE) {
@@ -1234,36 +1233,32 @@
return 0;
}
- c = string;
- while (*c) {
- d = c;
-
+ while (*string) {
i = 0;
- while (*d != '.' && *d && i <= DNS_MAX_LABEL_SIZE) {
- i++;
- if (!((*d == '-') || (*d == '_') ||
- ((*d >= 'a') && (*d <= 'z')) ||
- ((*d >= 'A') && (*d <= 'Z')) ||
- ((*d >= '0') && (*d <= '9')))) {
+ while (*string && *string != '.' && i < DNS_MAX_LABEL_SIZE) {
+ if (!(*string == '-' || *string == '_' ||
+ (*string >= 'a' && *string <= 'z') ||
+ (*string >= 'A' && *string <= 'Z') ||
+ (*string >= '0' && *string <= '9'))) {
if (err)
*err = DNS_INVALID_CHARACTER;
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)
*err = DNS_LABEL_TOO_LONG;
return 0;
}
- if (*d == '\0')
- goto out;
-
- c = ++d;
+ string++;
}
- out:
return 1;
}