Skip to content

src: fix potential segmentation fault in SQLite - #53850

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
tniessen:sqlite-check-empty
Jul 16, 2024
Merged

src: fix potential segmentation fault in SQLite#53850
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
tniessen:sqlite-check-empty

Conversation

@tniessen

Copy link
Copy Markdown
Member

The Local<Value> returned from ColumnToValue() and ColumnNameToValue() may be empty (if a JavaScript exception is pending), in which case a segmentation fault may occur at the call sites, which do not check if the Local<Value> is empty. Fix this bug by returning early if an exception is pending (as indicated by the Local being empty).

In the long term, these functions should return MaybeLocal instead of Local, but this patch is supposed to be a minimal bug fix only.

The Local<Value> returned from ColumnToValue() and ColumnNameToValue()
may be empty (if a JavaScript exception is pending), in which case a
segmentation fault may occur at the call sites, which do not check if
the Local<Value> is empty. Fix this bug returning early if an exception
is pending (as indicated by the Local being empty).
In the long term, these functions should return MaybeLocal instead of
Local, but this patch is supposed to be a minimal bug fix only.
@tniessentniessen added the sqlite Issues and PRs related to the SQLite subsystem. label Jul 14, 2024
@tniessen
tniessen requested a review from cjihrigJuly 14, 2024 21:54
@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. labels Jul 14, 2024
@tniessentniessen added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 14, 2024
@tniessentniessen added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 14, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 14, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@anonriganonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an easy repro?

@tniessen

Copy link
Copy Markdown
MemberAuthor

@anonrig The test case in #53851 segfaults without this PR :)

Comment threadsrc/node_sqlite.cc
Comment on lines +444 to +446
if (key.IsEmpty()) return;
Local<Value> val = stmt->ColumnToValue(i);
if (val.IsEmpty()) return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit... is it worth combining these into a single if (key.IsEmpty() || val.IsEmpty()) return just to make things a bit more compact?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We usually fail fast when a JavaScript exception is pending to avoid unsafe calls into JavaScript in that state. It seems that ColumnToValue() does not call into JavaScript, but unless someone feels strongly, I'd err on the side of caution here.

@tniessentniessen added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 16, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 16, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 0b1ff69 into nodejs:mainJul 16, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 0b1ff69

@tniessentniessen added the experimental Issues and PRs related to experimental features. label Jul 17, 2024
ehsankhfr pushed a commit to ehsankhfr/node that referenced this pull request Jul 18, 2024
The Local<Value> returned from ColumnToValue() and ColumnNameToValue()
may be empty (if a JavaScript exception is pending), in which case a
segmentation fault may occur at the call sites, which do not check if
the Local<Value> is empty. Fix this bug returning early if an exception
is pending (as indicated by the Local being empty).
In the long term, these functions should return MaybeLocal instead of
Local, but this patch is supposed to be a minimal bug fix only.
PR-URL: nodejs#53850
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
targos pushed a commit that referenced this pull request Jul 28, 2024
The Local<Value> returned from ColumnToValue() and ColumnNameToValue()
may be empty (if a JavaScript exception is pending), in which case a
segmentation fault may occur at the call sites, which do not check if
the Local<Value> is empty. Fix this bug returning early if an exception
is pending (as indicated by the Local being empty).
In the long term, these functions should return MaybeLocal instead of
Local, but this patch is supposed to be a minimal bug fix only.
PR-URL: #53850
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@RafaelGSSRafaelGSS mentioned this pull request Jul 30, 2024
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++.experimentalIssues and PRs related to experimental features.needs-ciPRs that need a full CI run.sqliteIssues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@tniessen@nodejs-github-bot@jasnell@anonrig@cjihrig@targos