Commit 3ece3fdb438 for nodejs
commit 3ece3fdb438928d74e97aaa09a488f51e77eaf8d
Author: Zelalem Habtamu <108578495+zelalem61@users.noreply.github.com>
Date: Mon Nov 23 19:43:27 2026 +0300
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>
diff --git a/lib/os.js b/lib/os.js
index 34b228c4edb..612e7171f7a 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -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);
diff --git a/test/parallel/test-os-negative-zero.js b/test/parallel/test-os-negative-zero.js
new file mode 100644
index 00000000000..7d355bb4c86
--- /dev/null
+++ b/test/parallel/test-os-negative-zero.js
@@ -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');
+ }
+}