os: fix abort on negative zero pid or priority

Fixes: https://github.com/nodejs/node/issues/67648
Assisted-by: Claude Code
Signed-off-by: Zelalem Habtamu <zelalemhab19@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67651
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This commit is contained in:
Zelalem Habtamu authored and Antoine du Hamel committed 2026-11-24 09:51:48 +01:00
1 parent 01470de44d
commit fc28b7070c
2 files changed
+29 -2

No files matched your search

+6 -2
View File
@@ -260,7 +260,9 @@ function setPriority(pid, priority) {
const ctx = {};
if (_setPriority(pid, priority, ctx) !== 0)
// V8 does not report -0 as an int32, so coerce it to 0 before it reaches
// the binding.
if (_setPriority(pid | 0, priority | 0, ctx) !== 0)
throw new ERR_SYSTEM_ERROR(ctx);
}
@@ -275,7 +277,9 @@ function getPriority(pid) {
validateInt32(pid, 'pid');
const ctx = {};
const priority = _getPriority(pid, ctx);
// V8 does not report -0 as an int32, so coerce it to 0 before it reaches
// the binding.
const priority = _getPriority(pid | 0, ctx);
if (priority === undefined)
throw new ERR_SYSTEM_ERROR(ctx);
+23
View File
@@ -0,0 +1,23 @@
'use strict';
require('../common');
const assert = require('assert');
const os = require('os');
// -0 passes the int32 validation, so it must be accepted like 0 instead of
// aborting the process in the binding.
assert.strictEqual(os.getPriority(-0), os.getPriority(0));
os.setPriority(-0, os.getPriority());
// Setting the priority to 0 may need more privileges than the process has,
// which is reported as a system error rather than an abort.
for (const args of [[0, -0], [-0, -0], [-0]]) {
try {
os.setPriority(...args);
} catch (err) {
assert.strictEqual(err.code, 'ERR_SYSTEM_ERROR');
assert.strictEqual(err.info.code, 'EACCES');
}
}