From c5d2a76407dea2f8256a7c68dbcf7c5e08be1690 Mon Sep 17 00:00:00 2001 From: Milos Ivanovic Date: Tue, 5 Sep 2017 11:57:07 +1200 Subject: [PATCH] Add NULL check --- sockssrv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sockssrv.c b/sockssrv.c index 7982914..bc76adf 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -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;