From bac3a485f6df6c1a0beb156ab78cf9c3d71dbe3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 17 Jul 2024 00:00:48 +0200 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. PR-URL: https://github.com/nodejs/node/pull/53850 Reviewed-By: Colin Ihrig Reviewed-By: Yagiz Nizipli --- 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;