From 91ecd7e3fc6dcfc8bf3b2dba8abe95631d46aea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 25 Aug 2024 12:43:17 +0200 Subject: [PATCH] sqlite: return results with null prototype These objects are dictionaries, and a query can return columns with special names like `__proto__` (which would be ignored without this change). Also construct the object by passing vectors of properties for better performance and improve error handling by using `MaybeLocal`. PR-URL: https://github.com/nodejs/node/pull/54350 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Yagiz Nizipli Reviewed-By: Franziska Hinkelmann Reviewed-By: James M Snell --- src/node_sqlite.cc | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 89dba430ed6b9b..a7745dd8d3a928 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -757,32 +757,23 @@ void StatementSync::All(const FunctionCallbackInfo& args) { auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); }); int num_cols = sqlite3_column_count(stmt->statement_); LocalVector rows(isolate); - LocalVector row_keys(isolate); while ((r = sqlite3_step(stmt->statement_)) == SQLITE_ROW) { - if (row_keys.size() == 0) { - row_keys.reserve(num_cols); - - for (int i = 0; i < num_cols; ++i) { - Local key; - if (!stmt->ColumnNameToName(i).ToLocal(&key)) return; - row_keys.emplace_back(key); - } - } - + LocalVector row_keys(isolate); + row_keys.reserve(num_cols); LocalVector row_values(isolate); row_values.reserve(num_cols); - for (size_t i = 0; i < row_keys.size(); ++i) { + for (int i = 0; i < num_cols; ++i) { + Local key; + if (!stmt->ColumnNameToName(i).ToLocal(&key)) return; Local val; if (!stmt->ColumnToValue(i).ToLocal(&val)) return; + row_keys.emplace_back(key); row_values.emplace_back(val); } - Local row = Object::New(isolate, - Null(isolate), - row_keys.data(), - row_values.data(), - row_keys.size()); + Local row = Object::New( + isolate, Null(isolate), row_keys.data(), row_values.data(), num_cols); rows.emplace_back(row); }