Bug 16208 - getaddrinfo() does not detect invalid numeric services
Summary: getaddrinfo() does not detect invalid numeric services
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2013-11-23 15:59 UTC by Shawn Landden
Modified: 2019-11-28 09:59 UTC (History)
3 users (show)

See Also:
Last reconfirmed:
fweimer: security-

proposed patch (548 bytes, patch)
2013-11-23 16:24 UTC, Shawn Landden
Details | Diff
proposed patch (550 bytes, patch)
2013-11-23 16:25 UTC, Shawn Landden
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Shawn Landden 2013-11-23 15:59:16 UTC
forwarded from Debian bug 192876

From: Martin Pool <mbp@sourcefrog.net>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: libc6: getaddrinfo() does not detect invalid numeric services
Date: Sun, 11 May 2003 13:00:17 +1000

Package: libc6
Version: 2.3.1-16
Severity: normal

By my reading of the getaddrinfo() manual (and also the Solaris
manpage) getaddrinfo() ought to return EAI_SERVICE when the requested
service is not available.  However, it does not seem to do this when
the service is a number, but out of the valid range 1-65535 for TCP

Here is a reproduction case:

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

/* try getaddrinfo */
int main(void)
	int err;
	struct addrinfo *res;
	struct addrinfo hints;

	bzero(&hints, sizeof hints);
 	hints.ai_family = AF_INET; 
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE;

	err = getaddrinfo(NULL, "80000", &hints, &res);
	printf("err=%d, %s\n", err, gai_strerror(err));

	return 0;

On my machine this returns 0, rather than the expected -8 "servname
not supported".

If I change "80000" to an invalid non-numeric string then the error
is flagged as expected.
Comment 1 Shawn Landden 2013-11-23 16:24:09 UTC
Created attachment 7299 [details]
proposed patch
Comment 2 Shawn Landden 2013-11-23 16:25:14 UTC
Created attachment 7300 [details]
proposed patch
Comment 3 Ondrej Bilka 2013-12-04 13:33:36 UTC
Could you send patch to libc-alpha@sourceware.org

You need to follow