From 3700d9edf78d512f9ddfd8c3a3baea9793815976 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 22 Jan 2023 11:39:16 +0100 Subject: [PATCH] src: fix c++ exception on bad command line arg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace stoull() with strtoull(). The former throws an exception when the input is malformed, the latter doesn't. Fixes: https://github.com/nodejs/node/issues/46223 PR-URL: https://github.com/nodejs/node/pull/46290 Reviewed-By: Colin Ihrig Reviewed-By: Darshan Sen Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- src/node_options-inl.h | 3 ++- test/sequential/test-cpu-prof-invalid-options.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 1ebe7ca405fd2d..ffc39a23b13378 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -444,7 +444,8 @@ void OptionsParser::Parse( *Lookup(info.field, options) = std::atoll(value.c_str()); break; case kUInteger: - *Lookup(info.field, options) = std::stoull(value); + *Lookup(info.field, options) = + std::strtoull(value.c_str(), nullptr, 10); break; case kString: *Lookup(info.field, options) = value; diff --git a/test/sequential/test-cpu-prof-invalid-options.js b/test/sequential/test-cpu-prof-invalid-options.js index b5f7619cdac0d8..d63716941f78cf 100644 --- a/test/sequential/test-cpu-prof-invalid-options.js +++ b/test/sequential/test-cpu-prof-invalid-options.js @@ -58,11 +58,11 @@ const { } // --cpu-prof-interval without --cpu-prof -{ +for (const arg of [kCpuProfInterval, 'crashme']) { tmpdir.refresh(); const output = spawnSync(process.execPath, [ '--cpu-prof-interval', - kCpuProfInterval, + arg, fixtures.path('workload', 'fibonacci.js'), ], { cwd: tmpdir.path,