Browse Source

Fix a potential issue in parse_addr

pull/1193/head
Max Lv 7 years ago
parent
commit
dde1bf7dec
3 changed files with 16 additions and 7 deletions
  1. 9
      src/jconf.c
  2. 8
      src/redir.c
  3. 6
      src/tunnel.c

9
src/jconf.c

@ -62,14 +62,17 @@ free_addr(ss_addr_t *addr)
}
void
parse_addr(const char *str, ss_addr_t *addr)
parse_addr(const char *str_in, ss_addr_t *addr)
{
if (str_in == NULL) return;
int ipv6 = 0, ret = -1, n = 0;
char *pch;
char *str = strdup(str_in);
struct cork_ip ip;
if (cork_ip_init(&ip, str) != -1) {
addr->host = strdup(str);
addr->host = str;
addr->port = NULL;
return;
}
@ -102,6 +105,8 @@ parse_addr(const char *str, ss_addr_t *addr)
}
addr->port = strdup(str + ret + 1);
}
free(str);
}
jconf_t *

8
src/redir.c

@ -943,6 +943,9 @@ main(int argc, char **argv)
if (plugin_opts == NULL) {
plugin_opts = conf->plugin_opts;
}
if (mode == TCP_ONLY) {
mode = conf->mode;
}
if (mtu == 0) {
mtu = conf->mtu;
}
@ -1046,11 +1049,12 @@ main(int argc, char **argv)
FATAL("failed to initialize ciphers");
// Setup proxy context
listen_ctx_t listen_ctx;
struct listen_ctx listen_ctx;
memset(&listen_ctx, 0, sizeof(struct listen_ctx));
listen_ctx.remote_num = remote_num;
listen_ctx.remote_addr = ss_malloc(sizeof(struct sockaddr *) * remote_num);
memset(listen_ctx.remote_addr, 0, sizeof(struct sockaddr *) * remote_num);
for (int i = 0; i < remote_num; i++) {
for (i = 0; i < remote_num; i++) {
char *host = remote_addr[i].host;
char *port = remote_addr[i].port == NULL ? remote_port :
remote_addr[i].port;

6
src/tunnel.c

@ -755,7 +755,7 @@ main(int argc, char **argv)
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0}
{ NULL, 0, NULL, 0 }
};
opterr = 0;
@ -1055,10 +1055,10 @@ main(int argc, char **argv)
int listenfd;
listenfd = create_and_bind(local_addr, local_port);
if (listenfd == -1) {
FATAL("bind() error:");
FATAL("bind() error");
}
if (listen(listenfd, SOMAXCONN) == -1) {
FATAL("listen() error:");
FATAL("listen() error");
}
setnonblocking(listenfd);

Loading…
Cancel
Save