Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ using v8::Value;
case SQLITE_TEXT: { \
const char* v = \
reinterpret_cast<const char*>(sqlite3_##from##_text(__VA_ARGS__)); \
(result) = String::NewFromUtf8((isolate), v).As<Value>(); \
Copy link
Contributor

@louwers louwers Jan 14, 2026

Choose a reason for hiding this comment

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

Strings returned by sqlite3_column_text() and sqlite3_column_text16(), even empty strings, are always zero-terminated.

If an out-of-memory error occurs, then the return value from these routines is the same as if the column had contained an SQL NULL value. Valid SQL NULL returns can be distinguished from out-of-memory errors by invoking the sqlite3_errcode() immediately after the suspect return value is obtained and before any other SQLite interface is called on the same database connection.

https://sqlite.org/c3ref/column_blob.html

If an OOM error occurs we should not just silently return null.

if (v == nullptr) { \
(result) = Null((isolate)); \
} else { \
(result) = String::NewFromUtf8((isolate), v).As<Value>(); \
} \
break; \
} \
case SQLITE_NULL: { \
Expand Down Expand Up @@ -246,7 +250,7 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, int errcode) {

Environment* env = Environment::GetCurrent(isolate);
Local<Object> error;
if (CreateSQLiteError(isolate, errstr).ToLocal(&error) &&
if (env && CreateSQLiteError(isolate, errstr).ToLocal(&error) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a problem because we assume Environment::GetCurrent(isolate) does not return null throughout the module.

error
->Set(isolate->GetCurrentContext(),
env->errcode_string(),
Expand Down
1 change: 1 addition & 0 deletions src/node_webstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Maybe<void> Storage::Open() {
sqlite3_stmt* s = nullptr;
r = sqlite3_prepare_v2(
db, get_schema_version_sql.data(), get_schema_version_sql.size(), &s, 0);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
Copy link
Contributor

@louwers louwers Jan 14, 2026

Choose a reason for hiding this comment

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

This looks legit.

r = sqlite3_exec(db, init_sql_v0.data(), 0, 0, nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
auto stmt = stmt_unique_ptr(s);
Expand Down