Skip to content

sqlite: check null returns from sqlite value functions - #63288

Open
ndossche wants to merge 1 commit into
nodejs:mainfrom
ndossche:clesss-6
Open

sqlite: check null returns from sqlite value functions#63288
ndossche wants to merge 1 commit into
nodejs:mainfrom
ndossche:clesss-6

Conversation

@ndossche

@ndossche ndossche commented May 13, 2026

Copy link
Copy Markdown
Contributor

sqlite3_column_text() can return nullptr on failure which was not handled. sqlite3_column_blob() can return nullptr for zero-length BLOBs, which is then passed to memcpy() which is UB. Avoid this by checking for a nullptr.

Note: this was found by a static-dynamic analyser I'm developing.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-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. sqlite Issues and PRs related to the SQLite subsystem. labels May 13, 2026
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (85d4755) to head (02db86a).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63288      +/-   ##
==========================================
- Coverage   90.30%   90.29%   -0.01%     
==========================================
  Files         759      759              
  Lines      247754   247754              
  Branches    46716    46720       +4     
==========================================
- Hits       223724   223719       -5     
- Misses      15483    15512      +29     
+ Partials     8547     8523      -24     
Files with missing lines Coverage Δ
src/node_sqlite.cc 80.84% <ø> (ø)

... and 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr

trivikr commented Aug 6, 2026

Copy link
Copy Markdown
Member

@ndossche Can you please rebase and force push?

sqlite3_column_text() can return nullptr on failure which
was not handled.
sqlite3_column_blob() can return nullptr for zero-length BLOBs,
which is then passed to memcpy() which is UB.
Avoid this by checking for a nullptr.

Signed-off-by: ndossche <nora.dossche@ugent.be>
@ndossche

ndossche commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Done, CI (so far) is looking okay

@trivikr

trivikr commented Aug 6, 2026

Copy link
Copy Markdown
Member

Can you add some regression tests? Ones which fail in main, but succeed with the fix?

@ndossche

ndossche commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Can you add some regression tests? Ones which fail in main, but succeed with the fix?

Apparently the current test suite can already trigger the "UB blob" problem, but the test runner ignores UBSAN failures, so you never see this as a failure.
Compile node.js with ubsan, and then set the environment variable export UBSAN_OPTIONS='print_stacktrace=1:halt_on_error=1' and then run: ./tools/test.py test/parallel/test-sqlite-data-types.js
This will show the failed test and crash backtrace.

As for the allocation failure in SQLITE_TEXT, I don't think I can make a reliable reproducer.

@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to 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-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants