Skip to content

Commit

Permalink
report: improve signal name validation
Browse files Browse the repository at this point in the history
PR-URL: #27137
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
cjihrig committed Apr 11, 2019
1 parent 5b9e570 commit 44a3acb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
const { convertToValidSignal } = require('internal/util');
const {
ERR_INVALID_ARG_TYPE,
ERR_SYNTHETIC
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const { validateSignalName, validateString } = require('internal/validators');
const nr = internalBinding('report');
const report = {
writeReport(file, err) {
Expand Down Expand Up @@ -47,8 +46,7 @@ const report = {
return nr.getSignal();
},
set signal(sig) {
validateString(sig, 'signal');
convertToValidSignal(sig); // Validate that the signal is recognized.
validateSignalName(sig, 'signal');
removeSignalHandler();
addSignalHandler(sig);
nr.setSignal(sig);
Expand Down
11 changes: 10 additions & 1 deletion test/report/test-report-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ if (!common.isWindows) {
}, { code: 'ERR_INVALID_ARG_TYPE' });
common.expectsError(() => {
process.report.signal = 'foo';
}, { code: 'ERR_UNKNOWN_SIGNAL' });
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: foo'
});
common.expectsError(() => {
process.report.signal = 'sigusr1';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: sigusr1 (signals must use all capital letters)'
});
assert.strictEqual(process.report.signal, 'SIGUSR2');
process.report.signal = 'SIGUSR1';
assert.strictEqual(process.report.signal, 'SIGUSR1');
Expand Down

0 comments on commit 44a3acb

Please sign in to comment.