Skip to content

Commit c4e5fde

Browse files
cjihrigindutny
authored andcommitted
child_process: copy spawnSync() cwd option to proper buffer
The spawnSync() cwd option was being copied to the incorrect location. This commit copies to the correct location. Closes nodejs#7824 Signed-off-by: Fedor Indutny <fedor@indutny.com>
1 parent 9452ea2 commit c4e5fde

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/spawn_sync.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
726726

727727
Local<Value> js_cwd = js_options->Get(env()->cwd_string());
728728
if (IsSet(js_cwd)) {
729-
r = CopyJsString(js_cwd, &uv_process_options_.cwd);
729+
r = CopyJsString(js_cwd, &cwd_buffer_);
730730
if (r < 0)
731731
return r;
732732
uv_process_options_.cwd = cwd_buffer_;

test/simple/test-child-process-execsync.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,19 @@ assert.deepEqual(ret, msgBuf);
8080
ret = execFileSync(process.execPath, args, { encoding: 'utf8' });
8181

8282
assert.strictEqual(ret, msg + '\n', 'execFileSync encoding result should match');
83+
84+
// Verify that the cwd option works - GH #7824
85+
(function() {
86+
var response;
87+
var cwd;
88+
89+
if (process.platform === 'win32') {
90+
cwd = 'c:\\';
91+
response = execSync('echo %cd%', {cwd: cwd});
92+
} else {
93+
cwd = '/';
94+
response = execSync('pwd', {cwd: cwd});
95+
}
96+
97+
assert.strictEqual(response.toString().trim(), cwd);
98+
})();

test/simple/test-child-process-spawnsync.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ assert.strictEqual(stop[0], 1, 'sleep should not take longer or less than 1 seco
4646
// Error test when command does not exist
4747
var ret_err = spawnSync('command_does_not_exist');
4848
assert.strictEqual(ret_err.error.code, 'ENOENT');
49+
50+
// Verify that the cwd option works - GH #7824
51+
(function() {
52+
var response;
53+
var cwd;
54+
55+
if (process.platform === 'win32') {
56+
cwd = 'c:\\';
57+
response = spawnSync('cmd.exe', ['/c', 'cd'], {cwd: cwd});
58+
} else {
59+
cwd = '/';
60+
response = spawnSync('pwd', [], {cwd: cwd});
61+
}
62+
63+
assert.strictEqual(response.stdout.toString().trim(), cwd);
64+
})();

0 commit comments

Comments
 (0)