Skip to content

Commit

Permalink
fixes nanomsg#127 Bad format TCP address causes null pointer exception
Browse files Browse the repository at this point in the history
I've added some tests to validate this too.
  • Loading branch information
gdamore committed Oct 23, 2017
1 parent d7fe2d3 commit fdb73b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ nni_tcp_parse_pair(char *pair, char **hostp, char **servp)
} else {
*hostp = host;
}
if (strlen(serv) == 0) {
if ((serv == NULL) || (strlen(serv) == 0)) {
*servp = NULL;
} else {
*servp = serv;
Expand Down
18 changes: 18 additions & 0 deletions tests/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,23 @@ TestMain("TCP Transport", {
So(nng_dial(s2, addr, NULL, 0) == 0);
});

Convey("Malformed TCP addresses do not panic", {
nng_socket s1;

So(nng_pair_open(&s1) == 0);
Reset({ nng_close(s1); });
So(nng_dial(s1, "tcp://127.0.0.1", NULL, 0) == NNG_EADDRINVAL);
So(nng_dial(s1, "tcp://127.0.0.1.32", NULL, 0) ==
NNG_EADDRINVAL);
So(nng_dial(s1, "tcp://127.0.x.1.32", NULL, 0) ==
NNG_EADDRINVAL);
So(nng_listen(s1, "tcp://127.0.0.1", NULL, 0) ==
NNG_EADDRINVAL);
So(nng_listen(s1, "tcp://127.0.0.1.32", NULL, 0) ==
NNG_EADDRINVAL);
So(nng_listen(s1, "tcp://127.0.x.1.32", NULL, 0) ==
NNG_EADDRINVAL);
});

nng_fini();
})
10 changes: 10 additions & 0 deletions tests/tcp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ check_props_v6(nng_msg *msg, nng_listener l, nng_dialer d)
So(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0);
});

Convey("Malformed TCPv6 addresses do not panic", {
nng_socket s1;

So(nng_pair_open(&s1) == 0);
Reset({ nng_close(s1); });
So(nng_dial(s1, "tcp://::1", NULL, 0) == NNG_EADDRINVAL);
So(nng_dial(s1, "tcp://::1:5055", NULL, 0) == NNG_EADDRINVAL);
So(nng_dial(s1, "tcp://[::1]", NULL, 0) == NNG_EADDRINVAL);
});

return (0);
}

Expand Down

0 comments on commit fdb73b6

Please sign in to comment.