8000 atf-c/utils.c:atf_utils_wait is not multiprocess safe · Issue #15 · freebsd/atf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

atf-c/utils.c:atf_utils_wait is not multiprocess safe #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jmmv opened this issue Sep 8, 2014 · 1 comment
Closed

atf-c/utils.c:atf_utils_wait is not multiprocess safe #15

jmmv opened this issue Sep 8, 2014 · 1 comment
Labels

Comments

@jmmv
Copy link
Member
jmmv commented Sep 8, 2014

Filed from freebsd/kyua#87 by yaneurabeya:

This code is writing to a non-temporary file with a constant filename in order to capture the exec output. This is not multiprocess/multithreading safe:

381 void
382 atf_utils_wait(const pid_t pid, const int exitstatus, const char *expout,
383                const char *experr)
384 {
385     int status;
386     ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
387
388     atf_utils_cat_file("atf_utils_fork_out.txt", "subprocess stdout: ");
389     atf_utils_cat_file("atf_utils_fork_err.txt", "subprocess stderr: ");
390
391     ATF_REQUIRE(WIFEXITED(status));
392     ATF_REQUIRE_EQ(exitstatus, WEXITSTATUS(status));
393
394     const char *save_prefix = "save:";
395     const size_t save_prefix_length = strlen(save_prefix);
396
397     if (strlen(expout) > save_prefix_length &&
398         strncmp(expout, save_prefix, save_prefix_length) == 0) {
399         atf_utils_copy_file("atf_utils_fork_out.txt",
400                             expout + save_prefix_length);
401     } else {
402         ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_out.txt", expout));
403     }
404
405     if (strlen(experr) > save_prefix_length &&
406         strncmp(experr, save_prefix, save_prefix_length) == 0) {
407         atf_utils_copy_file("atf_utils_fork_err.txt",
408                             experr + save_prefix_length);
409     } else {
410         ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_err.txt", experr));
411     }
412
413     ATF_REQUIRE(unlink("atf_utils_fork_out.txt") != -1);
414     ATF_REQUIRE(unlink("atf_utils_fork_err.txt") != -1);
415 }
@jmmv
Copy link
Member Author
jmmv commented Sep 8, 2014

There is currently no expectation for the ATF interface to be thread-safe.

But the problem here is not about threads: it's about multiprocessing. It's perfectly reasonable to spawn to subprocess and wait for them with checks, which fails with the current fork/wait interface.

As an easy solution, we can tag the generated file names with the spawned PID. Not completely bug-free if the OS decides to reuse PIDs along the way, but most decent OSs nowadays will avoid immediate PID reuse to prevent certain types of attacks.

@jmmv jmmv added the bug label Sep 8, 2014
@jmmv jmmv closed this as completed in 0e147fd Sep 11, 2014
lwhsu added a commit that referenced this issue Jan 16, 2024
atf-check.1: stop with extraneous quoting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0