Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
2dc1794085 Fix null pointer dereference in fromErrorInstance
The fromErrorInstance function in bindings.cpp was dereferencing null pointers:
1. The 'err' parameter was not null-checked before use
2. The 'obj' pointer from jsDynamicCast could be null

Added null checks to prevent crashes in error handling code:
- Early null check for 'err' parameter with fallback error message
- Conditional checks for 'obj' before all property access operations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 12:50:17 +00:00

View File

@@ -4707,6 +4707,13 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,
JSC::ErrorInstance* err, const Vector<JSC::StackFrame>* stackTrace,
JSC::JSValue val, PopulateStackTraceFlags flags)
{
// Early null check for err parameter
if (!err) {
except->name = Bun::toStringRef("Error"_s);
except->message = Bun::toStringRef("Unknown error"_s);
return;
}
JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(val);
auto& vm = JSC::getVM(global);
auto scope = DECLARE_CATCH_SCOPE(vm);
@@ -4731,10 +4738,14 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,
if (except->type == SYNTAX_ERROR_CODE) {
except->message = Bun::toStringRef(err->sanitizedMessageString(global));
} else if (JSC::JSValue message = obj->getIfPropertyExists(global, vm.propertyNames->message)) {
except->message = Bun::toStringRef(global, message);
if (!scope.clearExceptionExceptTermination()) [[unlikely]]
return;
} else if (obj) {
if (JSC::JSValue message = obj->getIfPropertyExists(global, vm.propertyNames->message)) {
except->message = Bun::toStringRef(global, message);
if (!scope.clearExceptionExceptTermination()) [[unlikely]]
return;
} else {
except->message = Bun::toStringRef(err->sanitizedMessageString(global));
}
} else {
except->message = Bun::toStringRef(err->sanitizedMessageString(global));
@@ -4752,7 +4763,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,
except->runtime_type = err->runtimeTypeForCause();
const auto& names = builtinNames(vm);
if (except->type != SYNTAX_ERROR_CODE) {
if (except->type != SYNTAX_ERROR_CODE && obj) {
JSC::JSValue syscall = getNonObservable(vm, global, obj, names.syscallPublicName());
if (!scope.clearExceptionExceptTermination()) [[unlikely]]
@@ -4806,7 +4817,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,
}
}
if (getFromSourceURL) {
if (getFromSourceURL && obj) {
{
// we don't want to serialize JSC::StackFrame longer than we need to