Skip to content

Commit

Permalink
Merge pull request zeromq#4149 from gummif/gfa/strtok
Browse files Browse the repository at this point in the history
Problem: strtok is not thread safe
  • Loading branch information
bluca authored Feb 21, 2021
2 parents c515671 + c325ed1 commit 4ecb045
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ws_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,16 @@ bool zmq::ws_engine_t::server_handshake ()
_header_upgrade_websocket =
strcasecmp ("websocket", _header_value) == 0;
else if (strcasecmp ("connection", _header_name) == 0) {
char *element = strtok (_header_value, ",");
char *rest = NULL;
char *element = strtok_r (_header_value, ",", &rest);
while (element != NULL) {
while (*element == ' ')
element++;
if (strcasecmp ("upgrade", element) == 0) {
_header_connection_upgrade = true;
break;
}
element = strtok (NULL, ",");
element = strtok_r (NULL, ",", &rest);
}
} else if (strcasecmp ("Sec-WebSocket-Key", _header_name)
== 0)
Expand All @@ -473,7 +474,7 @@ bool zmq::ws_engine_t::server_handshake ()
// 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[0] == '\0') {
char *rest = 0;
char *rest = NULL;
char *p = strtok_r (_header_value, ",", &rest);
while (p != NULL) {
if (*p == ' ')
Expand Down

0 comments on commit 4ecb045

Please sign in to comment.