-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
fix: address static analysis warnings in SQLite and WebStorage #61380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
bad94ff
6178b2c
c787428
550dcea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>(); \ | ||
| if (v == nullptr) { \ | ||
| THROW_ERR_MEMORY_ALLOCATION_FAILED(isolate); \ | ||
| } else { \ | ||
| (result) = String::NewFromUtf8((isolate), v).As<Value>(); \ | ||
| } \ | ||
| break; \ | ||
| } \ | ||
| case SQLITE_NULL: { \ | ||
|
|
@@ -111,7 +115,9 @@ using v8::Value; | |
| sqlite3_##from##_blob(__VA_ARGS__)); \ | ||
| auto store = ArrayBuffer::NewBackingStore( \ | ||
| (isolate), size, BackingStoreInitializationMode::kUninitialized); \ | ||
| memcpy(store->Data(), data, size); \ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; \ | ||
|
|
@@ -246,7 +252,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) && | ||
|
||
| error | ||
| ->Set(isolate->GetCurrentContext(), | ||
| env->errcode_string(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://sqlite.org/c3ref/column_blob.html
If an OOM error occurs we should not just silently return null.
There was a problem hiding this comment.
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