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
This commit is contained in:
parent
e257c93bbc
commit
e24e9d9988
@ -226,7 +226,7 @@ typedef union {
|
|||||||
u_char buf[MAXPACKET];
|
u_char buf[MAXPACKET];
|
||||||
} querybuf;
|
} querybuf;
|
||||||
|
|
||||||
static int str2number(const char *);
|
static int str2number(const char *, int *);
|
||||||
static int explore_null(const struct addrinfo *,
|
static int explore_null(const struct addrinfo *,
|
||||||
const char *, struct addrinfo **);
|
const char *, struct addrinfo **);
|
||||||
static int explore_numeric(const struct addrinfo *, const char *,
|
static int explore_numeric(const struct addrinfo *, const char *,
|
||||||
@ -341,7 +341,7 @@ freeaddrinfo(struct addrinfo *ai)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
str2number(const char *p)
|
str2number(const char *p, int *portp)
|
||||||
{
|
{
|
||||||
char *ep;
|
char *ep;
|
||||||
unsigned long v;
|
unsigned long v;
|
||||||
@ -351,9 +351,10 @@ str2number(const char *p)
|
|||||||
ep = NULL;
|
ep = NULL;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
v = strtoul(p, &ep, 10);
|
v = strtoul(p, &ep, 10);
|
||||||
if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
|
if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) {
|
||||||
return v;
|
*portp = v;
|
||||||
else
|
return 0;
|
||||||
|
} else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1327,7 +1328,7 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
|
|||||||
{
|
{
|
||||||
const char *proto;
|
const char *proto;
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
int port;
|
int port, error;
|
||||||
int allownumeric;
|
int allownumeric;
|
||||||
|
|
||||||
if (servname == NULL)
|
if (servname == NULL)
|
||||||
@ -1356,8 +1357,8 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
|
|||||||
return EAI_SOCKTYPE;
|
return EAI_SOCKTYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
port = str2number(servname);
|
error = str2number(servname, &port);
|
||||||
if (port >= 0) {
|
if (error == 0) {
|
||||||
if (!allownumeric)
|
if (!allownumeric)
|
||||||
return EAI_SERVICE;
|
return EAI_SERVICE;
|
||||||
if (port < 0 || port > 65535)
|
if (port < 0 || port > 65535)
|
||||||
|
Loading…
Reference in New Issue
Block a user