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
This commit is contained in:
Simon Wanner 2023-11-02 16:11:33 +01:00 committed by Andreas Kling
commit 1030776f92
Notes: sideshowbarker 2024-07-17 04:10:16 +09:00

View file

@ -93,6 +93,9 @@ void Error::populate_stack()
String Error::stack_string(CompactTraceback compact) const String Error::stack_string(CompactTraceback compact) const
{ {
if (m_traceback.is_empty())
return {};
StringBuilder stack_string_builder; StringBuilder stack_string_builder;
// Note: We roughly follow V8's formatting // Note: We roughly follow V8's formatting