dgram: fix abort on negative zero buffer size

The size check accepts -0, but the binding asserts IsUint32(),
which V8 reports as false for -0, so setRecvBufferSize(-0) and
setSendBufferSize(-0) abort the process. Coerce the value to +0.

Signed-off-by: JuHyeong424 <wkdwngud963@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67662
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
JuHyeong424 authored and Antoine du Hamel committed 2026-11-24 18:20:13 +01:00
1 parent b92011655a
commit dd2554d704
2 files changed
+14 -1

No files matched your search

+2 -1
View File
@@ -250,7 +250,8 @@ function bufferSize(self, size, buffer) {
throw new ERR_SOCKET_BAD_BUFFER_SIZE();
const ctx = {};
const ret = self[kStateSymbol].handle.bufferSize(size, buffer, ctx);
// Coerce -0 to +0, which the binding does not treat as a Uint32.
const ret = self[kStateSymbol].handle.bufferSize(size >>> 0, buffer, ctx);
if (ret === undefined) {
throw new ERR_SOCKET_BUFFER_SIZE(ctx);
}
+12
View File
@@ -0,0 +1,12 @@
'use strict';
const common = require('../common');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.bind(0, common.mustCall(() => {
socket.setRecvBufferSize(-0);
socket.setSendBufferSize(-0);
socket.close();
}));