From 959eabe2675a3b8be9bc2b2459cc899a5a64b283 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 22 May 2018 10:27:47 -0700 Subject: fixes #474 websocket listen on ws://*: fails fixes #464 Support NN_WS_MSG_TYPE option (compat) fixes #415 websocket does not honor recv maxsize This fixes a significant (and security) issue in websocket, where the code does not honor a maximum receive size. We've exposed new API (internal) to set the limit on the frame size, and we've changed the default to *unlimited* for that internal API. (But the default for SP sockets, which are the only consumers at present, is still 1MB just like all other SP transports.) --- src/compat/nanomsg/nn.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/compat') diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c index 564e60d8..bc27832e 100644 --- a/src/compat/nanomsg/nn.c +++ b/src/compat/nanomsg/nn.c @@ -748,6 +748,33 @@ nn_setignore(nng_socket s, const void *valp, size_t sz) return (0); } +static int +nn_getwsmsgtype(nng_socket s, void *valp, size_t *szp) +{ + int val = NN_WS_MSG_TYPE_BINARY; + NNI_ARG_UNUSED(s); + memcpy(valp, &val, *szp < sizeof(val) ? *szp : sizeof(val)); + *szp = sizeof(val); + return (0); +} + +static int +nn_setwsmsgtype(nng_socket s, const void *valp, size_t sz) +{ + int val; + NNI_ARG_UNUSED(s); + if (sz != sizeof(val)) { + nn_seterror(NNG_EINVAL); + return (-1); + } + memcpy(&val, valp, sizeof(val)); + if (val != NN_WS_MSG_TYPE_BINARY) { + nn_seterror(NNG_EINVAL); + return (-1); + } + return (0); +} + static int nn_settcpnodelay(nng_socket s, const void *valp, size_t sz) { @@ -1039,6 +1066,12 @@ static const struct { .nnopt = NN_TCP_NODELAY, .get = nn_gettcpnodelay, .set = nn_settcpnodelay, + }, + { + .nnlevel = NN_WS, + .nnopt = NN_WS_MSG_TYPE, + .get = nn_getwsmsgtype, + .set = nn_setwsmsgtype, } // XXX: IPV4ONLY, SNDPRIO, RCVPRIO }; -- cgit v1.2.3-70-g09d2