mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-22 06:21:45 +03:00
nsurl: Add support for IPv6 literals
Unfortunately, despite previous assertions to the contrary, we do need to deal with IPv6 literals. For now we validate just that they are encased by square brackets and consist only of hex digits and colons. We do not validate that they are actually valid IPv6 addresses. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
parent
1cf1391916
commit
553dc93ec8
@ -1263,6 +1263,9 @@ void nsurl__calc_hash(nsurl *url)
|
||||
* Valid hostnames are valid DNS names. This means they must consist only of
|
||||
* the ASCII characters a-z A-Z 0-9 '.', '_', or '-'.
|
||||
*
|
||||
* Unfortunately we also need to deal with IPv6 literals which are constrained
|
||||
* but strange. Surrounded by '[' and ']' there are hex digits and colons
|
||||
*
|
||||
* \param host The hostname to check
|
||||
* \return NSERROR_OK if the hostname is valid
|
||||
*/
|
||||
@ -1271,6 +1274,20 @@ static nserror nsurl__check_host_valid(lwc_string *host)
|
||||
const char *chptr = lwc_string_data(host);
|
||||
size_t nchrs = lwc_string_length(host);
|
||||
|
||||
if (*chptr == '[' && chptr[nchrs-1] == ']') {
|
||||
/* Treat this as an IPv6 Literal */
|
||||
chptr++;
|
||||
nchrs -= 2;
|
||||
while (nchrs--) {
|
||||
const char ch = *chptr++;
|
||||
if (!isxdigit(ch) && ch != ':') {
|
||||
/* Not hex digit or colon */
|
||||
return NSERROR_INVALID;
|
||||
}
|
||||
}
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
while (nchrs--) {
|
||||
const char ch = *chptr++;
|
||||
if (!isalnum(ch) && !(ch == '.' || ch == '-' || ch == '_')) {
|
||||
|
Loading…
Reference in New Issue
Block a user