Date: Wed, 29 Aug 2001 03:28:56 -0700 (PDT) From: John Morrow <jmorrow@inktomi.com> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/30186: getaddrinfo does not handle incorrect servname Message-ID: <200108291028.f7TASur75103@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 30186
>Category: misc
>Synopsis: getaddrinfo does not handle incorrect servname
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Aug 29 03:30:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: John Morrow
>Release: 4.4-PRERELEASE
>Organization:
>Environment:
FreeBSD dagobah.uk.inktomi.com 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #9: Mon Aug 6 12:29:02 BST 2001 jmorrow@dagobah.uk.inktomi.com:/usr/src/sys/compile/DAGOBAH i386
>Description:
If I call getaddrinfo("127.0.0.1", "80", &hints, &res) as a non-root
user and then bind using the returned socket address structure my
program is bound to the wrong address and port. I would have expected
a correctly filled out socket address structure and then a EACCESS
from bind(2).
$ ./a.out 127.0.0.1 80 & sockstat -l4 | grep a.out
jmorrow a.out 30004 3 tcp4 *:1045 *:*
$ ./a.out 127.0.0.1 8000 & sockstat -l4 | grep a.out
jmorrow a.out 30009 3 tcp4 127.0.0.1:8000 *:*
Also putting negative or high port numbers into this program
never causes getaddrinfo to return an error.
>How-To-Repeat:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int
main(int argc, char **argv)
{
struct addrinfo hints, *res;
int error, sock;
(void)memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(argv[1], argv[2], &hints, &res);
if ( error ) {
(void)printf("%s: %s\n", argv[1], gai_strerror(error));
return 1;
}
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
bind(sock, res->ai_addr, res->ai_addrlen);
listen(sock, 5);
sleep(60);
freeaddrinfo(res);
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108291028.f7TASur75103>
