public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Antonio Quartulli <a@unstable.cc>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: Andreas Schwab <schwab@suse.de>,
	Florian Weimer <fw@deneb.enyo.de>,
	Arne Schwabe <arne@rfc2549.org>,
	Cristina Nita-Rotaru <crisn@ccs.neu.edu>,
	Anqi Chen <chen.anqi3@northeastern.edu>
Subject: Re: [PATCH v4] nss: reject invalid port passed to getaddrinfo [BZ #16208]
Date: Fri, 1 Nov 2024 16:58:21 +0000	[thread overview]
Message-ID: <PAWPR08MB8982AD02C01077846DD53F4A83562@PAWPR08MB8982.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <acacc399-7117-459a-b352-7e9fbd1a813f@unstable.cc>

Hi Antonio,

> @@ -414,7 +414,7 @@ get_servtuples (const struct gaih_service *service, const struct addrinfo *req,
>     if (service != NULL && (tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
>       return -EAI_SERVICE;
>  
> -  if (service == NULL || service->num >= 0)
> +  if (service == NULL || (service->num >= 0 && service->num <= USHRT_MAX))

OK.

> @@ -2375,7 +2375,18 @@ getaddrinfo (const char *name, const char *service,
>              return EAI_NONAME;
>            }
>  
> -       gaih_service.num = -1;
> +       /* use an out-of-range value to report the parsing error */
> +       gaih_service.num = USHRT_MAX + 1;
> +     }
> +      /* port number must be in range [0, USHRT_MAX].
> +         Any other value is invalid.
> +         strtoul returns ULONG_MAX in case of out-of-range
> +         input and it is caught by this check */
> +      else if (gaih_service.num > USHRT_MAX)
> +     {
> +       /* the provided port number is invalid */
> +       __free_in6ai (in6ai);
> +       return EAI_NONAME;
>        }

So I'm still confused by this one - basically this treats "10000a" differently
from "100001". If the provided port number is a valid number but too large,
can we assume that AI_NUMERICSERV is set and return an error?

It may be better to treat it like an invalid port number, eg. something like:

      gaih_service.num = strtoul (gaih_service.name, &c, 10);
      /* port number must be a valid number with range [0, USHRT_MAX].
          strtoul returns ULONG_MAX in case of out-of-range.  */
      if (*c != '\0' || gaih_service.num > USHRT_MAX)
        {
          if (hints->ai_flags & AI_NUMERICSERV)
            {
              __free_in6ai (in6ai);
              return EAI_NONAME;
            }

          gaih_service.num = USHRT_MAX + 1;
        }

Cheers,
Wilco

  reply	other threads:[~2024-11-01 16:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30  0:07 Antonio Quartulli
2024-10-30  0:09 ` Antonio Quartulli
2024-11-01 16:58   ` Wilco Dijkstra [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-10-28 13:00 Wilco Dijkstra
2024-10-30  0:02 ` Antonio Quartulli
2024-10-17 10:50 Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAWPR08MB8982AD02C01077846DD53F4A83562@PAWPR08MB8982.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=a@unstable.cc \
    --cc=arne@rfc2549.org \
    --cc=chen.anqi3@northeastern.edu \
    --cc=crisn@ccs.neu.edu \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).