Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid parsing whitespace as invalid JSON #3208

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/transports/janus_websockets.c
Original file line number Diff line number Diff line change
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++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a dangerous check to me, though, since it's increasing the pointer and dereferencing it without ever checking if it got to the end and beyond (i.e., after incoming_end). This will crash if incoming_curr leaves the boundaries of the allocated space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this for a moment, but couldn't see how this could overflow. Still, I agree that it's better to be safe than sorry, so I pushed an update. Thanks for the feedback!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll make a couple of quick ckecks later (or tomorrow morning) and in case I can't spot any issue, I'll merge both PRs (thanks for providing a backported version too) 👍

if(incoming_curr == incoming_end) {
/* Process messages in order */
json_t **msg = message_buffer;
Expand Down