From b776bbdf15ff6de53794aa6203776c5e7182599b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 14 Jul 2024 21:50:26 +0000 Subject: [PATCH] src: fix potential segmentation fault in SQLite The Local returned from ColumnToValue() and ColumnNameToValue() may be empty (if a JavaScript exception is pending), in which case a segmentation fault may occur at the call sites, which do not check if the Local is empty. Fix this bug returning early if an exception is pending (as indicated by the Local being empty). In the long term, these functions should return MaybeLocal instead of Local, but this patch is supposed to be a minimal bug fix only. --- src/node_sqlite.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index cb7855a2ad1707..1202d2c8cf2464 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -441,7 +441,9 @@ void StatementSync::All(const FunctionCallbackInfo& args) { for (int i = 0; i < num_cols; ++i) { Local key = stmt->ColumnNameToValue(i); + if (key.IsEmpty()) return; Local val = stmt->ColumnToValue(i); + if (val.IsEmpty()) return; if (row->Set(env->context(), key, val).IsNothing()) { return; @@ -483,7 +485,9 @@ void StatementSync::Get(const FunctionCallbackInfo& args) { for (int i = 0; i < num_cols; ++i) { Local key = stmt->ColumnNameToValue(i); + if (key.IsEmpty()) return; Local val = stmt->ColumnToValue(i); + if (val.IsEmpty()) return; if (result->Set(env->context(), key, val).IsNothing()) { return;