Skip to content
Permalink
Browse files

report: improve signal name validation

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 8, 2019
1 parent 5b9e570 commit 44a3acb6272accf6296be521ff2f626514874acc
Showing with 12 additions and 5 deletions.
  1. +2 −4 lib/internal/process/report.js
  2. +10 −1 test/report/test-report-config.js
@@ -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) {
@@ -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);
@@ -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');

0 comments on commit 44a3acb

Please sign in to comment.
You can’t perform that action at this time.