Skip to content

Commit 198c95f

Browse files
committed
JS_ATOM_stack有可能获取不到,进而导致JS_ToCString返回nullptr,字符串连接访问空指针
1 parent e93b40c commit 198c95f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/PapiQuickjsImpl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,13 @@ const char* pesapi_get_exception_as_string(pesapi_scope scope, bool with_stack)
592592
//JSValue fileNameVal = JS_GetProperty(ctx, scope->caught->exception, JS_ATOM_fileName);
593593
//JSValue lineNumVal = JS_GetProperty(ctx, scope->caught->exception, JS_ATOM_lineNumber);
594594
JSValue stackVal = JS_GetProperty(ctx, scope->caught->exception, JS_ATOM_stack);
595-
auto stack = JS_ToCString(ctx, stackVal);
596-
scope->caught->message += "\n";
597-
scope->caught->message += stack;
598-
JS_FreeCString(ctx, stack);
595+
if (JS_IsString(stackVal))
596+
{
597+
auto stack = JS_ToCString(ctx, stackVal);
598+
scope->caught->message += "\n";
599+
scope->caught->message += stack;
600+
JS_FreeCString(ctx, stack);
601+
}
599602
JS_FreeValue(ctx, stackVal);
600603
}
601604
return scope->caught->message.c_str();

0 commit comments

Comments
 (0)