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

src: check for empty maybe local #32339

Closed
wants to merge 2 commits into from
Closed

src: check for empty maybe local #32339

wants to merge 2 commits into from

Conversation

Xstoudi
Copy link
Contributor

@Xstoudi Xstoudi commented Mar 18, 2020

Using ToLocalChecked on MaybeLocal without verify it's empty can lead to unattempted crash.

Before the change: this code leads Node.js to crash with C++ fatal error.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP. labels Mar 18, 2020
src/udp_wrap.cc Outdated
Comment on lines 519 to 521
MaybeLocal<Value> maybe_chunk = chunks->Get(env->context(), i);
if (maybe_chunk.IsEmpty()) return;
Local<Value> chunk = maybe_chunk.ToLocalChecked();
Copy link
Member

@himself65 himself65 Mar 18, 2020

Choose a reason for hiding this comment

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

Suggested change
MaybeLocal<Value> maybe_chunk = chunks->Get(env->context(), i);
if (maybe_chunk.IsEmpty()) return;
Local<Value> chunk = maybe_chunk.ToLocalChecked();
Local<Value> chunk;
if (!chunks->Get(env->context(), i).ToLocal(&chunk))
return;

This comment was marked as off-topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really sure about the value added by a test on this really really edge case.

Using ToLocalChecked on MaybeLocal without verifying it's empty can lead to unattempted crash.
@jasnell jasnell requested a review from addaleax March 18, 2020 23:40
@targos targos added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 20, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

addaleax pushed a commit that referenced this pull request Mar 27, 2020
Using ToLocalChecked on MaybeLocal without verifying it's empty
can lead to unattempted crash.

PR-URL: #32339
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax
Copy link
Member

Landed in 191fb3c, thanks for the PR! 🎉

@addaleax addaleax closed this Mar 27, 2020
addaleax pushed a commit that referenced this pull request Mar 30, 2020
Using ToLocalChecked on MaybeLocal without verifying it's empty
can lead to unattempted crash.

PR-URL: #32339
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Apr 22, 2020
Using ToLocalChecked on MaybeLocal without verifying it's empty
can lead to unattempted crash.

PR-URL: #32339
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants