Skip to content

Commit

Permalink
Fix: getaddrinfo misuse
Browse files Browse the repository at this point in the history
Closes #129
  • Loading branch information
zehome committed Mar 29, 2020
1 parent 80392b5 commit 49e1aca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mlvpn_control_init(struct mlvpn_control *ctrl)
ret = priv_getaddrinfo(ctrl->bindaddr, ctrl->bindport,
&res, &hints);
bak = res;
if (ret < 0 || ! res)
if (ret <= 0 || ! res)
{
log_warnx("control", "priv_getaddrinfo(%s,%s) failed: %s",
ctrl->bindaddr, ctrl->bindport,
Expand Down
4 changes: 2 additions & 2 deletions src/mlvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ mlvpn_rtun_bind(mlvpn_tunnel_t *t)
hints.ai_socktype = SOCK_DGRAM;

n = priv_getaddrinfo(t->bindaddr, t->bindport, &res, &hints);
if (n < 0)
if (n <= 0)
{
log_warnx(NULL, "%s getaddrinfo error: %s", t->name, gai_strerror(n));
return -1;
Expand Down Expand Up @@ -828,7 +828,7 @@ mlvpn_rtun_start(mlvpn_tunnel_t *t)
hints.ai_socktype = SOCK_DGRAM;

ret = priv_getaddrinfo(addr, port, &t->addrinfo, &hints);
if (ret < 0 || !t->addrinfo)
if (ret <= 0 || !t->addrinfo)
{
log_warnx("dns", "%s getaddrinfo(%s,%s) failed: %s",
t->name, addr, port, gai_strerror(ret));
Expand Down
6 changes: 3 additions & 3 deletions src/privsep.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ priv_init(char *argv[], char *username)
struct sigaction sa;
struct addrinfo hints, *res0, *res;
char hostname[MLVPN_MAXHNAMSTR], servname[MLVPN_MAXHNAMSTR];
char *phostname, *pservname;
char *phostname, *pservname = NULL;
char script_path[MAXPATHLEN] = {0};
char tuntapname[MLVPN_IFNAMSIZ];
char **script_argv;
Expand Down Expand Up @@ -339,7 +339,7 @@ priv_init(char *argv[], char *username)
else if (hostname_len > 0) {
must_read(socks[0], &hostname, hostname_len);
hostname[hostname_len - 1] = '\0';
phostname = hostname;
phostname = *hostname ? hostname : NULL;
} else {
phostname = NULL;
}
Expand All @@ -350,7 +350,7 @@ priv_init(char *argv[], char *username)
if (servname_len > 0) {
must_read(socks[0], &servname, servname_len);
servname[servname_len - 1] = '\0';
pservname = servname;
pservname = *servname ? servname : NULL;
} else {
pservname = NULL;
}
Expand Down

0 comments on commit 49e1aca

Please sign in to comment.