Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd38401

Browse filesBrowse files
Bryce Simondsevanlucas
authored andcommitted
src: fix Windows segfault with --eval
When specifing a parameter that requries an additional argument on the command line, node would segfault. This appears to be specific to Windows, adjusted command line argument parsing to hold a nullptr terminal. Adding unit test for crash on missing arguments. PR-URL: #6938 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent cd7c29e commit cd38401
Copy full SHA for cd38401

File tree

Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎src/node_main.cc‎

Copy file name to clipboardExpand all lines: src/node_main.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int wmain(int argc, wchar_t *wargv[]) {
1111
}
1212

1313
// Convert argv to to UTF8
14-
char** argv = new char*[argc];
14+
char** argv = new char*[argc + 1];
1515
for (int i = 0; i < argc; i++) {
1616
// Compute the size of the required buffer
1717
DWORD size = WideCharToMultiByte(CP_UTF8,
@@ -43,6 +43,7 @@ int wmain(int argc, wchar_t *wargv[]) {
4343
exit(1);
4444
}
4545
}
46+
argv[argc] = nullptr;
4647
// Now that conversion is done, we can finally start.
4748
return node::Start(argc, argv);
4849
}
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ child.exec(nodejs + ' --eval "console.error(42)"',
4040
assert.equal(stderr, '');
4141
});
4242

43-
child.exec(cmd + "'[]'",
43+
child.exec(cmd + "'[]'", common.mustCall(
4444
function(err, stdout, stderr) {
4545
assert.equal(stdout, '[]\n');
4646
assert.equal(stderr, '');
47-
});
47+
}));
4848
});
4949

5050
// assert that module loading works
@@ -66,6 +66,12 @@ child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"',
6666
assert.equal(status.code, 42);
6767
});
6868

69+
// Missing argument should not crash
70+
child.exec(nodejs + ' -e', common.mustCall(function(status, stdout, stderr) {
71+
assert.notStrictEqual(status, null);
72+
assert.strictEqual(status.code, 9);
73+
}));
74+
6975
// empty program should do nothing
7076
child.exec(nodejs + ' -e ""', function(status, stdout, stderr) {
7177
assert.equal(stdout, '');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.