Skip to content

Commit 472f586

Browse files
authored
os: freeze signals constant
Remove the ability to mutate signals constant as doing so can lead to unexpected behavior, notably when spawning child process. Fixes: #44749 PR-URL: #61038 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Aviv Keller <[email protected]>
1 parent 28f468a commit 472f586

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/os.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
ArrayPrototypePush,
2626
Float64Array,
2727
ObjectDefineProperties,
28+
ObjectFreeze,
2829
StringPrototypeSlice,
2930
SymbolToPrimitive,
3031
} = primordials;
@@ -330,6 +331,8 @@ module.exports = {
330331
machine: getMachine,
331332
};
332333

334+
ObjectFreeze(constants.signals);
335+
333336
ObjectDefineProperties(module.exports, {
334337
constants: {
335338
__proto__: null,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { test } = require('node:test');
5+
const assert = require('node:assert');
6+
const { constants } = require('node:os');
7+
8+
9+
test('Verify that signals constant is immutable', () => {
10+
assert.throws(() => constants.signals.FOOBAR = 1337, TypeError);
11+
});

0 commit comments

Comments
 (0)