diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-10-23 08:49:58 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-10-23 08:49:58 -0700 |
| commit | fdb73b69a887d868f8e976ef8a990a5d7f6687f9 (patch) | |
| tree | e6716c3837dfb85351f9bf1389bf510dc18daafe | |
| parent | d7fe2d325f25d339bb93fc86c2e63b71c6bbd575 (diff) | |
| download | nng-fdb73b69a887d868f8e976ef8a990a5d7f6687f9.tar.gz nng-fdb73b69a887d868f8e976ef8a990a5d7f6687f9.tar.bz2 nng-fdb73b69a887d868f8e976ef8a990a5d7f6687f9.zip | |
fixes #127 Bad format TCP address causes null pointer exception
I've added some tests to validate this too.
| -rw-r--r-- | src/transport/tcp/tcp.c | 2 | ||||
| -rw-r--r-- | tests/tcp.c | 18 | ||||
| -rw-r--r-- | tests/tcp6.c | 10 |
3 files changed, 29 insertions, 1 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 5ed90ca4..43b2890d 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -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; diff --git a/tests/tcp.c b/tests/tcp.c index 54ce26b0..79fe1893 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -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(); }) diff --git a/tests/tcp6.c b/tests/tcp6.c index 6f84d282..b1695c84 100644 --- a/tests/tcp6.c +++ b/tests/tcp6.c @@ -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); } |
