Skip to content

Commit

Permalink
Avoid parsing whitespace as invalid JSON when receiving WebSocket mes…
Browse files Browse the repository at this point in the history
…sages (#3208)
  • Loading branch information
htrendev committed May 4, 2023
1 parent 013155d commit d46bcb3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/transports/janus_websockets.c
Expand Up @@ -1347,6 +1347,9 @@ static int janus_websockets_common_callback(
incoming_curr += error.position;
JANUS_LOG(LOG_HUGE, "[%s-%p] Parsed JSON message - consumed %zu/%zu bytes\n",
log_prefix, wsi, (size_t)(incoming_curr - ws_client->incoming), incoming_length);
/* Trailing whitespace after the last message results in invalid JSON error */
while (incoming_curr < incoming_end && isspace(*incoming_curr))
incoming_curr++;
if(incoming_curr == incoming_end) {
/* Process messages in order */
json_t **msg = message_buffer;
Expand Down

0 comments on commit d46bcb3

Please sign in to comment.