From bad94ffbc1a7c29c34d828108cb02e7401adb242 Mon Sep 17 00:00:00 2001 From: GoldFish2500 Date: Wed, 14 Jan 2026 12:46:40 +0300 Subject: [PATCH 1/3] fix: address static analysis warnings in SQLite and WebStorage --- src/node_sqlite.cc | 8 ++++++-- src/node_webstorage.cc | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 6d35236dce0f82..1f407cdf1aea20 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -97,7 +97,11 @@ using v8::Value; case SQLITE_TEXT: { \ const char* v = \ reinterpret_cast(sqlite3_##from##_text(__VA_ARGS__)); \ - (result) = String::NewFromUtf8((isolate), v).As(); \ + if (v == nullptr) { \ + (result) = Null((isolate)); \ + } else { \ + (result) = String::NewFromUtf8((isolate), v).As(); \ + } \ break; \ } \ case SQLITE_NULL: { \ @@ -246,7 +250,7 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, int errcode) { Environment* env = Environment::GetCurrent(isolate); Local error; - if (CreateSQLiteError(isolate, errstr).ToLocal(&error) && + if (env && CreateSQLiteError(isolate, errstr).ToLocal(&error) && error ->Set(isolate->GetCurrentContext(), env->errcode_string(), diff --git a/src/node_webstorage.cc b/src/node_webstorage.cc index 0b301a310fa397..5ce8611f3de05d 100644 --- a/src/node_webstorage.cc +++ b/src/node_webstorage.cc @@ -177,6 +177,7 @@ Maybe 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()); r = sqlite3_exec(db, init_sql_v0.data(), 0, 0, nullptr); CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing()); auto stmt = stmt_unique_ptr(s); From 6178b2c6f04f3c6ab8fde2d1ca2fe94bdf8a06dd Mon Sep 17 00:00:00 2001 From: GoldFish2500 Date: Thu, 9 Apr 2026 12:19:42 +0300 Subject: [PATCH 2/3] throw ALLOCATION_FAILED exception. memcpy UB prevent --- src/node_sqlite.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 1f407cdf1aea20..a59634598d9147 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -98,7 +98,7 @@ using v8::Value; const char* v = \ reinterpret_cast(sqlite3_##from##_text(__VA_ARGS__)); \ if (v == nullptr) { \ - (result) = Null((isolate)); \ + THROW_ERR_MEMORY_ALLOCATION_FAILED(isolate); \ } else { \ (result) = String::NewFromUtf8((isolate), v).As(); \ } \ @@ -115,7 +115,9 @@ using v8::Value; sqlite3_##from##_blob(__VA_ARGS__)); \ auto store = ArrayBuffer::NewBackingStore( \ (isolate), size, BackingStoreInitializationMode::kUninitialized); \ - memcpy(store->Data(), data, size); \ + if (data) { \ + memcpy(store->Data(), data, size); \ + } \ auto ab = ArrayBuffer::New((isolate), std::move(store)); \ (result) = Uint8Array::New(ab, 0, size); \ break; \ From c7874288142ac3964c0841e1f3c539e364c77f7c Mon Sep 17 00:00:00 2001 From: GoldFish2500 Date: Thu, 9 Apr 2026 12:32:00 +0300 Subject: [PATCH 3/3] env pointer checking removed --- src/node_sqlite.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index a59634598d9147..1ee8e38499e718 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -252,7 +252,7 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, int errcode) { Environment* env = Environment::GetCurrent(isolate); Local error; - if (env && CreateSQLiteError(isolate, errstr).ToLocal(&error) && + if (CreateSQLiteError(isolate, errstr).ToLocal(&error) && error ->Set(isolate->GetCurrentContext(), env->errcode_string(),