On 25/05/2024 12:06, NetSurf Browser Project (Commit Mailer) wrote:
> - Log -----------------------------------------------------------------
> commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=553dc93ec8f414f475e4e6d5e66e0a7d6131da96
> commit 553dc93ec8f414f475e4e6d5e66e0a7d6131da96
> Author: Daniel Silverstone <dsilvers@digital-scurf.org>
> Commit: Daniel Silverstone <dsilvers@digital-scurf.org>
>
> 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>
>
> diff --git a/utils/nsurl/parse.c b/utils/nsurl/parse.c
> index 06b6601e0..541248e11 100644
> --- a/utils/nsurl/parse.c
> +++ b/utils/nsurl/parse.c
> @@ -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 == '_')) {
You probably want to use the locale-agnostic helpers in utils/ascii.h:
s/isalnum/ascii_is_alphanumerical/
s/isxdigit/ascii_is_hex/
Otherwise, the behaviour of nsurl__check_host_valid will depend upon the
locale, which is rarely what we want anywhere in NetSurf.
J.
No comments:
Post a Comment