mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
sqlite: check null returns from sqlite value functions
sqlite3_column_text() can return nullptr on failure which was not handled. sqlite3_column_blob() can return nullptr for zero-length BLOBs, which is then passed to memcpy() which is UB. Avoid this by checking for a nullptr. Signed-off-by: ndossche <nora.dossche@ugent.be> PR-URL: https://github.com/nodejs/node/pull/63288 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
3458dead5a
commit
330f7b5503
1 file changed
+7
-1
+7
-1
@@ -121,6 +121,10 @@ inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate,
|
||||
case SQLITE_TEXT: { \
|
||||
const char* v = \
|
||||
reinterpret_cast<const char*>(sqlite3_##from##_text(__VA_ARGS__)); \
|
||||
if (v == nullptr) [[unlikely]] { \
|
||||
THROW_ERR_MEMORY_ALLOCATION_FAILED((isolate)); \
|
||||
break; \
|
||||
} \
|
||||
const int v_len = sqlite3_##from##_bytes(__VA_ARGS__); \
|
||||
(result) = \
|
||||
Utf8StringMaybeOneByte((isolate), std::string_view(v, v_len)) \
|
||||
@@ -138,7 +142,9 @@ inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate,
|
||||
sqlite3_##from##_blob(__VA_ARGS__)); \
|
||||
auto store = ArrayBuffer::NewBackingStore( \
|
||||
(isolate), size, BackingStoreInitializationMode::kUninitialized); \
|
||||
memcpy(store->Data(), data, size); \
|
||||
if (data != nullptr) [[likely]] { \
|
||||
memcpy(store->Data(), data, size); \
|
||||
} \
|
||||
auto ab = ArrayBuffer::New((isolate), std::move(store)); \
|
||||
(result) = Uint8Array::New(ab, 0, size); \
|
||||
break; \
|
||||
|
||||
Reference in new issue
Block a user