aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHajimu UMEMOTO <ume@FreeBSD.org>2006-07-23 15:31:03 +0000
committerHajimu UMEMOTO <ume@FreeBSD.org>2006-07-23 15:31:03 +0000
commite24e9d998838177448222a10d94a18def655178c (patch)
tree87ab6d7d35ed35667791f578db36a0a309850e15 /lib
parente257c93bbcfd2736d99fe479c20b6468c3decb4c (diff)
downloadsrc-e24e9d998838177448222a10d94a18def655178c.tar.gz
src-e24e9d998838177448222a10d94a18def655178c.zip
do not overload the port number on to the return value of
str2number(). this could result in an unexpected code path. Obtained from: KAME MFC after: 1 week
Notes
Notes: svn path=/head/; revision=160593
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index c7bdfa3b70cf..11742b90aa69 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -226,7 +226,7 @@ typedef union {
u_char buf[MAXPACKET];
} querybuf;
-static int str2number(const char *);
+static int str2number(const char *, int *);
static int explore_null(const struct addrinfo *,
const char *, struct addrinfo **);
static int explore_numeric(const struct addrinfo *, const char *,
@@ -341,7 +341,7 @@ freeaddrinfo(struct addrinfo *ai)
}
static int
-str2number(const char *p)
+str2number(const char *p, int *portp)
{
char *ep;
unsigned long v;
@@ -351,9 +351,10 @@ str2number(const char *p)
ep = NULL;
errno = 0;
v = strtoul(p, &ep, 10);
- if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
- return v;
- else
+ if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) {
+ *portp = v;
+ return 0;
+ } else
return -1;
}
@@ -1327,7 +1328,7 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
{
const char *proto;
struct servent *sp;
- int port;
+ int port, error;
int allownumeric;
if (servname == NULL)
@@ -1356,8 +1357,8 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
return EAI_SOCKTYPE;
}
- port = str2number(servname);
- if (port >= 0) {
+ error = str2number(servname, &port);
+ if (error == 0) {
if (!allownumeric)
return EAI_SERVICE;
if (port < 0 || port > 65535)