Compare commits

...

1 Commits

Author SHA1 Message Date
Claude
8eeec5c046 fix(socket): handle non-object argument in Listener.getsockname
Listener.getsockname() assumed its first argument was always an object
and called .put() on it unconditionally. When a non-object value (e.g.
an integer) was passed, .getObject() returned null in the C++ binding
JSC__JSValue__putBunString, causing a null pointer dereference at
BunString.cpp:942.

Create a new empty object when the argument is not an object, matching
the expected behavior of populating and returning address info.

Reproduction:
```js
function f6(a7, a8) { return a7; }
const v9 = { data: f6 };
const v11 = Bun.listen({ hostname: "localhost", port: 0, socket: v9 });
v11.getsockname(1); // crashes with null pointer deref
v11.stop(true);
```
2026-02-20 22:32:31 +00:00

View File

@@ -850,7 +850,8 @@ pub fn getsockname(this: *Listener, globalThis: *jsc.JSGlobalObject, callFrame:
return .js_undefined;
}
const out = callFrame.argumentsAsArray(1)[0];
const arg = callFrame.argumentsAsArray(1)[0];
const out = if (arg.isObject()) arg else JSValue.createEmptyObject(globalThis, 3);
const socket = this.listener.uws;
var buf: [64]u8 = [_]u8{0} ** 64;