mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 20:16:54 +03:00
stop idna (en/de)code asploding when the passed host begins with a .
This commit is contained in:
parent
2462f5658e
commit
16dea2e2bd
22
utils/idna.c
22
utils/idna.c
@ -600,7 +600,12 @@ idna_encode(const char *host, size_t len, char **ace_host, size_t *ace_len)
|
||||
char fqdn[256];
|
||||
char *output, *fqdn_p = fqdn;
|
||||
|
||||
while ((label_len = idna__host_label_length(host, len)) != 0) {
|
||||
label_len = idna__host_label_length(host, len);
|
||||
if (label_len == 0) {
|
||||
return NSERROR_BAD_URL;
|
||||
}
|
||||
|
||||
while (label_len != 0) {
|
||||
if (idna__is_ldh(host, label_len) == false) {
|
||||
/* This string is IDN or invalid */
|
||||
|
||||
@ -649,6 +654,8 @@ idna_encode(const char *host, size_t len, char **ace_host, size_t *ace_len)
|
||||
}
|
||||
host++;
|
||||
len = len - label_len - 1;
|
||||
|
||||
label_len = idna__host_label_length(host, len);
|
||||
}
|
||||
|
||||
fqdn_p--;
|
||||
@ -670,7 +677,12 @@ idna_decode(const char *ace_host, size_t ace_len, char **host, size_t *host_len)
|
||||
char fqdn[256];
|
||||
char *output, *fqdn_p = fqdn;
|
||||
|
||||
while ((label_len = idna__host_label_length(ace_host, ace_len)) != 0) {
|
||||
label_len = idna__host_label_length(ace_host, ace_len);
|
||||
if (label_len == 0) {
|
||||
return NSERROR_BAD_URL;
|
||||
}
|
||||
|
||||
while (label_len != 0) {
|
||||
if (idna__is_ace(ace_host, label_len) == true) {
|
||||
/* This string is DNS-valid and (probably) encoded */
|
||||
|
||||
@ -705,9 +717,13 @@ idna_decode(const char *ace_host, size_t ace_len, char **host, size_t *host_len)
|
||||
fqdn_len++;
|
||||
|
||||
ace_host += label_len;
|
||||
if ((*ace_host == '\0') || (*ace_host == ':')) break;
|
||||
if ((*ace_host == '\0') || (*ace_host == ':')) {
|
||||
break;
|
||||
}
|
||||
ace_host++;
|
||||
ace_len = ace_len - label_len - 1;
|
||||
|
||||
label_len = idna__host_label_length(ace_host, ace_len);
|
||||
}
|
||||
|
||||
fqdn_p--;
|
||||
|
Loading…
Reference in New Issue
Block a user