Skip to content

Conversation

@gabrielschulhof
Copy link
Contributor

When napi_create_string_* receives a null pointer as its second
argument, it must null-check it before passing it into V8, otherwise a
crash will occur.

Signed-off-by: @gabrielschulhof

@github-actionsgithub-actionsbot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 4, 2021
@gabrielschulhofgabrielschulhof added node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests. labels Jun 4, 2021
When `napi_create_string_*` receives a null pointer as its second argument, it must null-check it before passing it into V8, otherwise a crash will occur. Signed-off-by: Gabriel Schulhof <[email protected]>
@gabrielschulhofgabrielschulhofforce-pushed the node-api-fix-string-null branch from e86316d to b5dc717CompareJune 4, 2021 06:38
Copy link
Member

@mhdawsonmhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@addaleaxaddaleax left a comment

Choose a reason for hiding this comment

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

str should be allowed to be nullptr if length is 0.

@gabrielschulhof
Copy link
ContributorAuthor

@addaleax I added an allowance for NULL when the length given is zero. PTAL!

@nodejs-github-bot
Copy link
Collaborator

napi_value* result){
CHECK_ENV(env);
if (length > 0)
CHECK_ARG(env, str);
Copy link
Member

Choose a reason for hiding this comment

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

The naming of these macros is really unfortunate. Everywhere else, CHECK_* generally implies an assert.

@mhdawson
Copy link
Member

@nodejs-github-bot
Copy link
Collaborator

gabrielschulhof added a commit that referenced this pull request Jun 11, 2021
When `napi_create_string_*` receives a null pointer as its second argument, it must null-check it before passing it into V8, otherwise a crash will occur. Signed-off-by: Gabriel Schulhof <[email protected]> PR-URL: #38923 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
@gabrielschulhof
Copy link
ContributorAuthor

Landed in d615aeb.

@gabrielschulhofgabrielschulhof deleted the node-api-fix-string-null branch June 11, 2021 16:04
danielleadams pushed a commit that referenced this pull request Jun 13, 2021
When `napi_create_string_*` receives a null pointer as its second argument, it must null-check it before passing it into V8, otherwise a crash will occur. Signed-off-by: Gabriel Schulhof <[email protected]> PR-URL: #38923 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
@danielleadamsdanielleadams mentioned this pull request Jun 14, 2021
danielleadams pushed a commit that referenced this pull request Jun 17, 2021
When `napi_create_string_*` receives a null pointer as its second argument, it must null-check it before passing it into V8, otherwise a crash will occur. Signed-off-by: Gabriel Schulhof <[email protected]> PR-URL: #38923 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
@richardlau
Copy link
Member

This is blocked from landing on v14.x-staging as it depends on #37217.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.needs-ciPRs that need a full CI run.node-apiIssues and PRs related to the Node-API.testIssues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@gabrielschulhof@nodejs-github-bot@mhdawson@richardlau@fhinkel@jasnell@addaleax@legendecas@bl-ue