Skip to content

Commit eee1de9

Browse files
jeffhostetlerdscho
authored andcommitted
sub-process: do not borrow cmd pointer from caller
Teach subprocess_start() to use a copy of the passed `cmd` string rather than borrowing the buffer from the caller. Some callers of subprocess_start() pass the value returned from find_hook() which points to a static buffer and therefore is only good until the next call to find_hook(). This could cause problems for the long-running background processes managed by sub-process.c where later calls to subprocess_find_entry() to get an existing process will fail. This could cause more than 1 long-running process to be created. TODO Need to confirm, but if only read_object_hook() uses TODO subprocess_start() in this manner, we could drop this TODO commit when we drop support for read_object_hook(). Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
1 parent a33a33b commit eee1de9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sub-process.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
7878
int err;
7979
struct child_process *process;
8080

81-
entry->cmd = cmd;
81+
// BUGBUG most callers to subprocess_start() pass in "cmd" the value
82+
// BUGBUG of find_hook() which returns a static buffer (that's only
83+
// BUGBUG good until the next call to find_hook()).
84+
// BUGFIX Defer assignment until we copy the string in our argv.
85+
// entry->cmd = cmd;
86+
8287
process = &entry->process;
8388

8489
child_process_init(process);
@@ -90,6 +95,8 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
9095
process->clean_on_exit_handler = subprocess_exit_handler;
9196
process->trace2_child_class = "subprocess";
9297

98+
entry->cmd = process->args.v[0];
99+
93100
err = start_command(process);
94101
if (err) {
95102
error("cannot fork to run subprocess '%s'", cmd);

0 commit comments

Comments
 (0)