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
10 changes: 8 additions & 2 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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
Copy Markdown
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

agree that hiding OOM is not acceptable. I suggest throwing an appropriate exception

if (v == nullptr) { \
THROW_ERR_MEMORY_ALLOCATION_FAILED(isolate); \
} else { \
(result) = String::NewFromUtf8((isolate), v).As<Value>(); \
} \
break; \
} \
case SQLITE_NULL: { \
Expand All @@ -119,7 +123,9 @@ using v8::Value;
sqlite3_##from##_blob(__VA_ARGS__)); \
auto store = ArrayBuffer::NewBackingStore( \
(isolate), size, BackingStoreInitializationMode::kUninitialized); \
memcpy(store->Data(), data, size); \
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I suggest adding the pointer check to prevent UB. The behavior will not change, but the static analyzer will stop triggering.

if (data) { \
memcpy(store->Data(), data, size); \
} \
auto ab = ArrayBuffer::New((isolate), std::move(store)); \
(result) = Uint8Array::New(ab, 0, size); \
break; \
Expand Down
1 change: 1 addition & 0 deletions src/node_webstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Maybe<void> Storage::Open() {
get_schema_version_sql.size(),
&s,
nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
Copy link
Copy Markdown
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(), nullptr, nullptr, nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
auto stmt = stmt_unique_ptr(s);
Expand Down