From 29c6d4e0a2f7d0627fbfaa6589b5c4e40689ca57 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 17 Feb 2019 22:35:48 -0800 Subject: fixes #821 http_server crash when using url without hostname --- src/supplemental/http/http_server.c | 6 ++---- tests/ws.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 939273b7..cb003aff 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -866,13 +866,11 @@ http_server_init(nni_http_server **serverp, const nni_url *url) return (rv); } - if ((strlen(url->u_port)) && - ((s->port = nni_strdup(url->u_port)) == NULL)) { + if ((s->port = nni_strdup(url->u_port)) == NULL) { http_server_fini(s); return (NNG_ENOMEM); } - if ((strlen(url->u_hostname)) && - ((s->hostname = nni_strdup(url->u_hostname)) == NULL)) { + if ((s->hostname = nni_strdup(url->u_hostname)) == NULL) { http_server_fini(s); return (NNG_ENOMEM); } diff --git a/tests/ws.c b/tests/ws.c index e126cb39..e5cc8ba5 100644 --- a/tests/ws.c +++ b/tests/ws.c @@ -140,5 +140,20 @@ TestMain("WebSocket Transport", { So(nng_dial(s2, addr, NULL, 0) == NNG_ECONNREFUSED); }); + // This test covers bug 821. + Convey("Double wildcard listen works", { + nng_socket s1; + nng_socket s2; + So(nng_pair_open(&s1) == 0); + So(nng_pair_open(&s2) == 0); + Reset({ + nng_close(s1); + nng_close(s2); + }); + So(nng_listen(s1, "ws://*:5599/one", NULL, 0) == 0); + So(nng_listen(s1, "ws://*:5599/two", NULL, 0) == 0); + So(nng_dial(s2, "ws://127.0.0.1:5599/one", NULL, 0) == 0); + }); + nng_fini(); }) -- cgit v1.2.3-70-g09d2