GeezerVison is showing github.com — sqlite: check null returns from sqlite value functions · nodejs/node@b8faee0
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_sqlite.cc +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -121,6 +121,10 @@ inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate, |
121 | 121 | case SQLITE_TEXT: { \ |
122 | 122 | const char* v = \ |
123 | 123 | reinterpret_cast<const char*>(sqlite3_##from##_text(__VA_ARGS__)); \ |
| 124 | + if (v == nullptr) [[unlikely]] { \ |
| 125 | + THROW_ERR_MEMORY_ALLOCATION_FAILED((isolate)); \ |
| 126 | + break; \ |
| 127 | + } \ |
124 | 128 | const int v_len = sqlite3_##from##_bytes(__VA_ARGS__); \ |
125 | 129 | (result) = \ |
126 | 130 | Utf8StringMaybeOneByte((isolate), std::string_view(v, v_len)) \ |
@@ -138,7 +142,9 @@ inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate, |
138 | 142 | sqlite3_##from##_blob(__VA_ARGS__)); \ |
139 | 143 | auto store = ArrayBuffer::NewBackingStore( \ |
140 | 144 | (isolate), size, BackingStoreInitializationMode::kUninitialized); \ |
141 | | - memcpy(store->Data(), data, size); \ |
| 145 | + if (data != nullptr) [[likely]] { \ |
| 146 | + memcpy(store->Data(), data, size); \ |
| 147 | + } \ |
142 | 148 | auto ab = ArrayBuffer::New((isolate), std::move(store)); \ |
143 | 149 | (result) = Uint8Array::New(ab, 0, size); \ |
144 | 150 | break; \ |
|