Skip to content

Commit 8f51878

Browse files
author
Archkon
authored
sea: avoid dangling CLI option pointers
Reserve exec argv storage before inserting configured and CLI-expanded arguments so vector reallocation cannot invalidate pointers in argv. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: #64755 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent cf44862 commit 8f51878

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/node_sea.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,11 @@ std::tuple<int, char**> FixupArgsForSEA(int argc,
325325
cli_extension_args.size() + 2);
326326
new_argv.emplace_back(argv[0]);
327327

328+
exec_argv_storage.reserve(sea_resource.exec_argv.size() +
329+
cli_extension_args.size());
330+
328331
// Insert exec argv from SEA config
329332
if (!sea_resource.exec_argv.empty()) {
330-
exec_argv_storage.reserve(sea_resource.exec_argv.size() +
331-
cli_extension_args.size());
332333
for (const auto& arg : sea_resource.exec_argv) {
333334
exec_argv_storage.emplace_back(arg);
334335
new_argv.emplace_back(exec_argv_storage.back().data());

test/fixtures/sea/exec-argv-extension-cli/sea-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"main": "sea.js",
33
"output": "sea-prep.blob",
44
"disableExperimentalSEAWarning": true,
5-
"execArgv": ["--no-warnings"],
65
"execArgvExtension": "cli"
76
}

test/fixtures/sea/exec-argv-extension-cli/sea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const assert = require('assert');
33
console.log('process.argv:', JSON.stringify(process.argv));
44
console.log('process.execArgv:', JSON.stringify(process.execArgv));
55

6-
// Should have execArgv from SEA config + CLI --node-options
6+
// Should have all options from CLI --node-options
77
assert.deepStrictEqual(process.execArgv, ['--no-warnings', '--max-old-space-size=1024']);
88

99
assert.deepStrictEqual(process.argv.slice(2), [

test/sea/test-single-executable-application-exec-argv-extension-cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ const env = {
3030
// Test that --node-options works with execArgvExtension: "cli"
3131
spawnSyncAndAssert(
3232
outputFile,
33-
['--node-options=--max-old-space-size=1024', 'user-arg1', 'user-arg2'],
33+
[
34+
'--node-options=--no-warnings --max-old-space-size=1024',
35+
'user-arg1',
36+
'user-arg2',
37+
],
3438
{
3539
env,
3640
},

0 commit comments

Comments
 (0)