Compare commits

...

3 Commits

Author SHA1 Message Date
Meghan Denny
5c3ea0bf44 Merge remote-tracking branch 'origin/main' into nektro-patch-10080 2025-06-19 16:33:14 -07:00
nektro
2f2c1057ba bun run prettier 2025-06-10 23:10:30 +00:00
Meghan Denny
720a007ae1 node:net: fix crash calling getsockname on native server handle [v2] 2025-06-10 15:44:04 -07:00
3 changed files with 34 additions and 0 deletions

View File

@@ -782,6 +782,7 @@ pub fn getsockname(this: *Listener, globalThis: *JSC.JSGlobalObject, callFrame:
}
const out = callFrame.argumentsAsArray(1)[0];
if (!out.isObject()) return globalThis.throwInvalidArgumentTypeValue("sockname", "object", out);
const socket = this.listener.uws;
var buf: [64]u8 = [_]u8{0} ** 64;

View File

@@ -590,6 +590,20 @@ if (expect.extend)
message: () => `Expected ${actual} to be a UTF16 string`,
};
},
// meant to be called like `expect(() => ....).not.toCrash()`
// when fuzzing exposed internals, the important piece is that it finishes without sefaulting, not whether it throws an error or not
toCrash(fn: unknown) {
if (typeof fn !== "function") throw new Error("toCrash expects a function");
try {
fn();
} catch (e) {
// ignore
}
return {
pass: false,
message: () => `Expected 'fn' to cause a crash`,
};
},
});
export function ospath(path: string) {

View File

@@ -686,3 +686,22 @@ it("connectionListener should emit the right amount of times, and with alpnProto
await Promise.all(promises);
expect(count).toBe(50);
});
describe("should fuzz the native handle and not crash", () => {
const handle = require("tls").Server().listen().unref()._handle;
const proto = Object.getPrototypeOf(handle);
const descs = Object.getOwnPropertyDescriptors(proto);
for (const k in descs) {
for (const v of [undefined, null, "", "a", 24, -3.4, {}, [], Symbol("b")]) {
it(`${k}(${String(v)})`, () => {
const descriptor = descs[k];
expect(() => descriptor.get?.call(handle)).not.toCrash();
if (typeof descriptor.value !== "function") return;
expect(() => descriptor.value.call(handle, v)).not.toCrash();
expect(() => descriptor.value.call(undefined, v)).not.toCrash();
expect(() => descriptor.value.call(null, v)).not.toCrash();
expect(() => descriptor.set?.call(handle, v)).not.toCrash();
});
}
}
});