Skip to content

Commit 8fac4c5

Browse files
deokjinkimjuanarbol
authored andcommitted
perf_hooks: fix checking range of options.figures in createHistogram
For `options.figures`, number between 1 and 5 is allowed. So need to use `validateInteger` to limit max as 5. Refs: https://github.com/nodejs/node/blob/main/doc/api/perf_hooks.md#perf_hookscreatehistogramoptions PR-URL: #45999 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 7e1462d commit 8fac4c5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/internal/histogram.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const {
3636
validateInteger,
3737
validateNumber,
3838
validateObject,
39-
validateUint32,
4039
} = require('internal/validators');
4140

4241
const kDestroy = Symbol('kDestroy');
@@ -368,7 +367,7 @@ function createHistogram(options = kEmptyObject) {
368367
} else if (highest < 2n * lowest) {
369368
throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest);
370369
}
371-
validateUint32(figures, 'options.figures', 1, 5);
370+
validateInteger(figures, 'options.figures', 1, 5);
372371
return internalRecordableHistogram(new _Histogram(lowest, highest, figures));
373372
}
374373

test/parallel/test-perf-hooks-histogram.js

+7
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ const { inspect } = require('util');
135135
});
136136
});
137137

138+
// Number greater than 5 is not allowed
139+
for (const i of [6, 10]) {
140+
throws(() => createHistogram({ figures: i }), {
141+
code: 'ERR_OUT_OF_RANGE',
142+
});
143+
}
144+
138145
createHistogram({ lowest: 1, highest: 11, figures: 1 });
139146
}
140147

0 commit comments

Comments
 (0)