Commit 1450681f authored by Denis Collette's avatar Denis Collette

Problem: Issue #3766 states that strtok is not thread safe and should be replaced

Solution: Replaced calls to strtok with strtok_r (strtok_s for windows)
in ws_engine.cpp
parent b7dd31db
...@@ -73,6 +73,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -73,6 +73,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
#define strcasecmp _stricmp #define strcasecmp _stricmp
#define strtok_r strtok_s
#else #else
#ifdef ZMQ_HAVE_LIBBSD #ifdef ZMQ_HAVE_LIBBSD
#include <bsd/string.h> #include <bsd/string.h>
...@@ -487,7 +488,8 @@ bool zmq::ws_engine_t::server_handshake () ...@@ -487,7 +488,8 @@ bool zmq::ws_engine_t::server_handshake ()
// Sec-WebSocket-Protocol can appear multiple times or be a comma separated list // Sec-WebSocket-Protocol can appear multiple times or be a comma separated list
// if _websocket_protocol is already set we skip the check // if _websocket_protocol is already set we skip the check
if (_websocket_protocol[0] == '\0') { if (_websocket_protocol[0] == '\0') {
char *p = strtok (_header_value, ","); char *rest;
char *p = strtok_r (_header_value, ",", &rest);
while (p != NULL) { while (p != NULL) {
if (*p == ' ') if (*p == ' ')
p++; p++;
...@@ -497,7 +499,7 @@ bool zmq::ws_engine_t::server_handshake () ...@@ -497,7 +499,7 @@ bool zmq::ws_engine_t::server_handshake ()
break; break;
} }
p = strtok (NULL, ","); p = strtok_r (NULL, ",", &rest);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment