From 2c5dfef393ad4122242689dc79e1064e70df2cd8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 26 Aug 2018 02:34:05 +0200 Subject: [PATCH] src: fix NODE_OPTIONS parsing bug I, uhm, might have messed up by using a `substr(start, end)` signature when `std::string` actually uses `substr(start, len)`. Fix that. Fixes: https://github.com/nodejs/node/issues/22526 Refs: https://github.com/nodejs/node/pull/22392 PR-URL: https://github.com/nodejs/node/pull/22529 Reviewed-By: Gus Caplan Reviewed-By: Ruben Bridgewater Reviewed-By: Refael Ackermann Reviewed-By: Trivikram Kamat --- src/node.cc | 3 ++- test/parallel/test-cli-node-options.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/node.cc b/src/node.cc index 97102700f65800..81cf4526526cbb 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2921,7 +2921,8 @@ void Init(std::vector* argv, index = node_options.find(' ', index + 1); if (index - prev_index == 1) continue; - const std::string option = node_options.substr(prev_index + 1, index); + const std::string option = node_options.substr( + prev_index + 1, index - prev_index - 1); if (!option.empty()) env_argv.emplace_back(std::move(option)); } while (index != std::string::npos); diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js index d851f225fcbc35..c7096a3acb55f7 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -14,7 +14,9 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); process.chdir(tmpdir.path); -expect(`-r ${require.resolve('../fixtures/printA.js')}`, 'A\nB\n'); +const printA = require.resolve('../fixtures/printA.js'); +expect(`-r ${printA}`, 'A\nB\n'); +expect(`-r ${printA} -r ${printA}`, 'A\nB\n'); expect('--no-deprecation', 'B\n'); expect('--no-warnings', 'B\n'); expect('--trace-warnings', 'B\n'); @@ -29,6 +31,9 @@ expect('--v8-pool-size=10', 'B\n'); expect('--trace-event-categories node', 'B\n'); // eslint-disable-next-line no-template-curly-in-string expect('--trace-event-file-pattern {pid}-${rotation}.trace_events', 'B\n'); +// eslint-disable-next-line no-template-curly-in-string +expect('--trace-event-file-pattern {pid}-${rotation}.trace_events ' + + '--trace-event-categories node.async_hooks', 'B\n'); if (!common.isWindows) { expect('--perf-basic-prof', 'B\n');