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 426aa0a

Browse filesBrowse files
Bryce SimondsMyles Borins
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 9cccaa3 commit 426aa0a
Copy full SHA for 426aa0a

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
@@ -3,7 +3,7 @@
33
#ifdef _WIN32
44
int wmain(int argc, wchar_t *wargv[]) {
55
// Convert argv to to UTF8
6-
char** argv = new char*[argc];
6+
char** argv = new char*[argc + 1];
77
for (int i = 0; i < argc; i++) {
88
// Compute the size of the required buffer
99
DWORD size = WideCharToMultiByte(CP_UTF8,
@@ -35,6 +35,7 @@ int wmain(int argc, wchar_t *wargv[]) {
3535
exit(1);
3636
}
3737
}
38+
argv[argc] = nullptr;
3839
// Now that conversion is done, we can finally start.
3940
return node::Start(argc, argv);
4041
}
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
@@ -59,6 +59,12 @@ child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"',
5959
assert.equal(status.code, 42);
6060
});
6161

62+
// Missing argument should not crash
63+
child.exec(nodejs + ' -e', common.mustCall(function(status, stdout, stderr) {
64+
assert.notStrictEqual(status, null);
65+
assert.strictEqual(status.code, 9);
66+
}));
67+
6268
// empty program should do nothing
6369
child.exec(nodejs + ' -e ""', function(status, stdout, stderr) {
6470
assert.equal(stdout, '');

0 commit comments

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