Compare commits

...

1 Commits

Author SHA1 Message Date
Henrik Böving
bd4bf582ca fix: move allocation of execvp args before fork 2026-01-23 14:12:56 +00:00

View File

@@ -442,6 +442,13 @@ static obj_res spawn(string_ref const & proc_name, array_ref<string_ref> const &
auto stdout_pipe = setup_stdio(stdout_mode);
auto stderr_pipe = setup_stdio(stderr_mode);
// It is crucial to not allocate between `fork` and `execvp` for ASAN to work.
buffer<char *> pargs;
pargs.push_back(strdup(proc_name.data()));
for (auto & arg : args)
pargs.push_back(strdup(arg.data()));
pargs.push_back(NULL);
int pid = fork();
if (pid == 0) {
@@ -495,12 +502,6 @@ static obj_res spawn(string_ref const & proc_name, array_ref<string_ref> const &
lean_always_assert(setsid() >= 0);
}
buffer<char *> pargs;
pargs.push_back(strdup(proc_name.data()));
for (auto & arg : args)
pargs.push_back(strdup(arg.data()));
pargs.push_back(NULL);
if (execvp(pargs[0], pargs.data()) < 0) {
std::cerr << "could not execute external process '" << pargs[0] << "'" << std::endl;
exit(-1);
@@ -509,6 +510,12 @@ static obj_res spawn(string_ref const & proc_name, array_ref<string_ref> const &
throw errno;
}
for (char* parg : pargs) {
if (parg != NULL) {
free(parg);
}
}
object * parent_stdin = box(0);
object * parent_stdout = box(0);
object * parent_stderr = box(0);