Skip to content

wasi: remove unecessary null check - #42819

Merged
nodejs-github-bot merged 1 commit into
nodejs:masterfrom
mhdawson:coverity-20
Apr 24, 2022
Merged

wasi: remove unecessary null check#42819
nodejs-github-bot merged 1 commit into
nodejs:masterfrom
mhdawson:coverity-20

Conversation

@mhdawson

Copy link
Copy Markdown
Member

As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.

Signed-off-by: Michael Dawson mdawson@devrus.com

As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/wasi

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. wasi Issues and PRs related to the WebAssembly System Interface. labels Apr 21, 2022
@mhdawson

Copy link
Copy Markdown
MemberAuthor

From coverity

Local<Array> env_pairs = args[1].As<Array>();
201constuint32_t envc = env_pairs->Length();
202 options.envp = const_cast<constchar**>(newchar*[envc + 1]);
203for (uint32_t i = 0; i < envc; i++) {
204auto pair = env_pairs->Get(context, i).ToLocalChecked();
205CHECK(pair->IsString());
206 node::Utf8Value str(env->isolate(), pair);
deref_ptr: Directly dereferencing pointer options.envp.
207 options.envp[i] = strdup(*str);
208CHECK_NOT_NULL(options.envp[i]);
209 }
...
CID239687 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking options.envp suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
239 if (options.envp != nullptr) {
240for (uint32_t i = 0; options.envp[i]; i++)
241free(const_cast<char*>(options.envp[i]));
242delete[] options.envp;
243 }

@RaisinTenRaisinTen added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 24, 2022
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@tniessentniessen added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 24, 2022
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 24, 2022
@nodejs-github-bot
nodejs-github-bot merged commit 503f147 into nodejs:masterApr 24, 2022
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 503f147

xtx1130 pushed a commit to xtx1130/node that referenced this pull request Apr 25, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: nodejs#42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this pull request Apr 28, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: #42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
@targostargos mentioned this pull request May 2, 2022
juanarbol pushed a commit that referenced this pull request May 31, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: #42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
danielleadams pushed a commit that referenced this pull request Jun 27, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: #42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this pull request Jul 12, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: #42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this pull request Jul 31, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: #42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
@targostargos mentioned this pull request Aug 3, 2022
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
As reported by coverity the null check is
done after earlier code has already derefenced
options.envp. Either we should null check earlier
uses or this check is not necessary. Since options.envp
is created with new which should throw an
exception intead of returning null, it should
be safe to assume the null check is not required.
Signed-off-by: Michael Dawson <mdawson@devrus.com>
PR-URL: nodejs/node#42819
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs 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++.needs-ciPRs that need a full CI run.wasiIssues and PRs related to the WebAssembly System Interface.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mhdawson@nodejs-github-bot@lpinca@tniessen@RaisinTen