This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] getaddrinfo: return EAI_SERVICE when TCP or UDP port out of 1-65535 range
- From: Pavel Simerda <psimerda at redhat dot com>
- To: Shawn Landden <shawn at churchofgit dot com>
- Cc: libc-alpha at sourceware dot org, Siddhesh Poyarekar <siddhesh at redhat dot com>, "Carlos O'Donell" <codonell at redhat dot com>
- Date: Wed, 4 Dec 2013 11:14:40 -0500 (EST)
- Subject: Re: [PATCH] getaddrinfo: return EAI_SERVICE when TCP or UDP port out of 1-65535 range
- Authentication-results: sourceware.org; auth=none
- References: <1386169354-101169-1-git-send-email-shawn at churchofgit dot com>
----- Original Message -----
> From: "Shawn Landden" <shawn@churchofgit.com>
> To: libc-alpha@sourceware.org
> Cc: "Shawn Landden" <shawn@churchofgit.com>
> Sent: Wednesday, December 4, 2013 4:02:34 PM
> Subject: [PATCH] getaddrinfo: return EAI_SERVICE when TCP or UDP port out of 1-65535 range
The patch doesn't look entirely right:
1) Existing application might use service="0" if they want to fill in the port later for some reason. And I personally think it's a valid use case as the behavior of service="0" shouldn't IMO be the same as of service=NULL. I propose to leave out the zero check.
See: https://sourceware.org/bugzilla/show_bug.cgi?id=14990
2) There are other values of socktype than the enumerated ones including zero. I propose to avoid checking the socktype.
Also, I was maybe waiting too long with my patch fixing the bug I mentioned above and cleaning up the service/servname stuff. I'll post it ASAP and I'll include the port upper bound check. In the meantime, I don't have any strong preference as whether to add the upper bound check to the current code or not, I would list like to have #1 and #2 taken into consideration.
Cheers,
Pavel
> Reported-by: Martin Pool <mbp@sourcefrog.net>
> Signed-off-by: Shawn Landden <shawn@churchofgit.com>
> ---
> sysdeps/posix/getaddrinfo.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
> index 8218237..5b3b10d 100644
> --- a/sysdeps/posix/getaddrinfo.c
> +++ b/sysdeps/posix/getaddrinfo.c
> @@ -2391,6 +2391,12 @@ getaddrinfo (const char *name, const char *service,
>
> gaih_service.num = -1;
> }
> + else if ((hints->ai_family == AF_INET || hints->ai_family == AF_INET6)
> + && (hints->ai_socktype == SOCK_STREAM || hints->ai_socktype
> == SOCK_DGRAM)
> + && (gaih_service.num == 0 || gaih_service.num > 65535))
> + {
> + return EAI_SERVICE;
> + }
>
> pservice = &gaih_service;
> }
> --
> 1.8.5
>
>