Skip to content

sqlite: check sqlite3_step() and sqlite3_reset() results#63319

Open
semimikoh wants to merge 1 commit into
nodejs:mainfrom
semimikoh:sqlite/check-step-reset-returns
Open

sqlite: check sqlite3_step() and sqlite3_reset() results#63319
semimikoh wants to merge 1 commit into
nodejs:mainfrom
semimikoh:sqlite/check-step-reset-returns

Conversation

@semimikoh

Copy link
Copy Markdown
Contributor

Summary

Per the SQLite docs, sqlite3_reset(S) may return a deferred error code
from the prior sqlite3_step(S) call. Several statement execution paths in
src/node_sqlite.cc dropped that return value, which could silently ignore
SQLite errors.

This also checks the previously ignored sqlite3_step() result in
StatementExecutionHelper::Run().

Fixes: #63311

Approach

Successful execution paths now explicitly check sqlite3_reset().

Functions with early-return or V8-exception paths keep an OnScopeLeave
reset guard so prepared statements are left reusable. The guard intentionally
drops the reset result to avoid replacing an already-pending SQLite or V8
exception.

StatementSyncIterator::Next() and StatementSyncIterator::Return() use a
direct checked reset because their control flow is linear.

$ python3 tools/cpplint.py src/node_sqlite.cc

Done processing src/node_sqlite.cc

$ git diff --check -- src/node_sqlite.cc

A full local build was not completed because this machine has Apple clang
16.0.0, while the current tree requires a newer macOS toolchain. The build
fails in V8 because std::atomic_ref is unavailable.

@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 15, 2026
@semimikoh semimikoh force-pushed the sqlite/check-step-reset-returns branch 2 times, most recently from fd05a3c to 557bcde Compare May 15, 2026 05:26
Signed-off-by: semimikoh <ejffjeosms@gmail.com>
@semimikoh semimikoh force-pushed the sqlite/check-step-reset-returns branch from 557bcde to 4740589 Compare May 15, 2026 05:40
@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.44444% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.05%. Comparing base (2edd842) to head (4740589).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 69.44% 2 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63319      +/-   ##
==========================================
+ Coverage   90.04%   90.05%   +0.01%     
==========================================
  Files         714      714              
  Lines      225338   225361      +23     
  Branches    42598    42614      +16     
==========================================
+ Hits       202897   202942      +45     
+ Misses      14236    14190      -46     
- Partials     8205     8229      +24     
Files with missing lines Coverage Δ
src/node_sqlite.cc 80.35% <69.44%> (-0.28%) ⬇️

... and 34 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.

@geeksilva97

Copy link
Copy Markdown
Contributor

I tried to reproduce a situation where the current code wouldn't catch the error but I couldn't. Please, get such a case into a test so it's clear which situation we must cover.

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.

Unchecked sqlite3 API calls

3 participants