From 01829a762c05c305dc54ba211c4a493b8471dc43 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Wed, 28 Dec 2022 23:43:45 +0900 Subject: [PATCH] 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 --- lib/internal/histogram.js | 3 +-- test/parallel/test-perf-hooks-histogram.js | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index ca540e555e0160..92a679e8f3a634 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -36,7 +36,6 @@ const { validateInteger, validateNumber, validateObject, - validateUint32, } = require('internal/validators'); const kDestroy = Symbol('kDestroy'); @@ -368,7 +367,7 @@ function createHistogram(options = kEmptyObject) { } else if (highest < 2n * lowest) { throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest); } - validateUint32(figures, 'options.figures', 1, 5); + validateInteger(figures, 'options.figures', 1, 5); return internalRecordableHistogram(new _Histogram(lowest, highest, figures)); } diff --git a/test/parallel/test-perf-hooks-histogram.js b/test/parallel/test-perf-hooks-histogram.js index 1bcc59653bb692..37fcdfb3fca06c 100644 --- a/test/parallel/test-perf-hooks-histogram.js +++ b/test/parallel/test-perf-hooks-histogram.js @@ -135,6 +135,13 @@ const { inspect } = require('util'); }); }); + // Number greater than 5 is not allowed + for (const i of [6, 10]) { + throws(() => createHistogram({ figures: i }), { + code: 'ERR_OUT_OF_RANGE', + }); + } + createHistogram({ lowest: 1, highest: 11, figures: 1 }); }