Skip to content

Commit

Permalink
Add NULL check
Browse files Browse the repository at this point in the history
  • Loading branch information
milosivanovic committed Sep 4, 2017
1 parent 9da94f6 commit c5d2a76
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sockssrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ static int connect_socks_target(unsigned char *buf, size_t n, struct client *cli
}
}

local.sin_family = AF_INET;
local.sin_port = 0;
local.sin_addr.s_addr = inet_addr(bind_ip);
if(bind_ip != NULL) {

// bind before connect to use the listen address as the outgoing address
if(bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0)
goto eval_errno;
local.sin_family = AF_INET;
local.sin_port = 0;
local.sin_addr.s_addr = inet_addr(bind_ip);

// bind before connect to use the listen address as the outgoing address
if(bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0)
goto eval_errno;
}

if(connect(fd, remote->ai_addr, remote->ai_addrlen) == -1)
goto eval_errno;
Expand Down

0 comments on commit c5d2a76

Please sign in to comment.