From 1030776f92ffa19aa0e642e295c0fcc169c5ab78 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Thu, 2 Nov 2023 16:11:33 +0100 Subject: [PATCH] LibJS: Avoid crash on empty stack trace We were trying to stringify the stack trace without the last element, leading to a loop bound of (size_t)(0 - 1) and accessing m_traceback[0] out-of-bounds. Instead, just return an empty string in that case. Fixes #21747 --- Userland/Libraries/LibJS/Runtime/Error.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index 07b3121b93..fb7f6c6bf6 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -93,6 +93,9 @@ void Error::populate_stack() String Error::stack_string(CompactTraceback compact) const { + if (m_traceback.is_empty()) + return {}; + StringBuilder stack_string_builder; // Note: We roughly follow V8's formatting