From 68b880987484ee101a207f2cb59d451bc263d5ac Mon Sep 17 00:00:00 2001 From: OhOkThisIsFine <102485413+OhOkThisIsFine@users.noreply.github.com> Date: Sat, 29 Aug 2026 14:43:59 -0700 Subject: [PATCH] fix(tests): copy the runner, not /bin/cat, as the POSIX blocked image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit daemon_runtime_process_fingerprint_never_hashes_replacement_path (POSIX variant) copied /bin/cat to a temp file named "image" and executed the copy. On Ubuntu 25.10+/26.04 and any other uutils system, /bin/cat is a multi-call binary: a copy invoked under the name "image" prints "coreutils: unknown program 'image'" and exits 1, so the fixture died at ASSERT(setup). Reproduced on WSL Ubuntu 26.04 (uutils coreutils 0.8.0). The Windows variant of the same test already avoids this class of donor: it copies the test runner itself and parks it in a __cbm_runtime_image_holder argv mode. The POSIX variant now does the same. The holder mode gains a POSIX branch that blocks reading stdin until EOF — exactly the behaviour the cat donor provided — and runtime_test_spawn_blocked_executable passes the holder argument, so its target must now be a copy of this runner (it has exactly one caller). The /bin/echo replacement donor is gone too: it was only ever hashed, never executed, and on a uutils system cat and echo can be the same multi-call bytes, which would have broken the fixture's original != replacement precondition. The replacement is now a small data file, mirroring the Windows variant. No signing change is needed on macOS: the image copy stays byte-identical to the runner, and the identical-copy fixture already proves such a copy executes. daemon_runtime suite on WSL Ubuntu 26.04: 44 passed / 0 failed. Co-Authored-By: Claude Fable 5 Signed-off-by: OhOkThisIsFine <102485413+OhOkThisIsFine@users.noreply.github.com> --- tests/test_daemon_runtime.c | 19 ++++++++++++++++--- tests/test_main.c | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/test_daemon_runtime.c b/tests/test_daemon_runtime.c index 5f41d914e..793395d03 100644 --- a/tests/test_daemon_runtime.c +++ b/tests/test_daemon_runtime.c @@ -382,6 +382,9 @@ static bool runtime_test_copy_executable(const char *source, const char *destina return ok; } +/* PATH must be a copy of this runner: the child runs the + * __cbm_runtime_image_holder mode, which blocks reading the release pipe + * wired to its stdin. */ static pid_t runtime_test_spawn_blocked_executable(const char *path, int *release_fd_out) { int ready[2] = {-1, -1}; int input[2] = {-1, -1}; @@ -427,7 +430,7 @@ static pid_t runtime_test_spawn_blocked_executable(const char *path, int *releas if (input[0] != STDIN_FILENO) { (void)posix_spawn_file_actions_addclose(&actions, input[0]); } - char *const child_argv[] = {(char *)path, NULL}; + char *const child_argv[] = {(char *)path, "__cbm_runtime_image_holder", NULL}; pid_t child = -1; if (posix_spawn(&child, path, &actions, NULL, child_argv, environ) != 0) { child = -1; @@ -4518,10 +4521,20 @@ TEST(daemon_runtime_process_fingerprint_never_hashes_replacement_path) { int replacement_written = setup ? snprintf(replacement_path, sizeof(replacement_path), "%s/replacement", directory) : -1; + /* The copied image is this runner in holder mode, not a system utility: + * a multi-call coreutils /bin/cat (uutils) prints "unknown program" and + * exits when executed under the copied name. */ setup = setup && image_written > 0 && image_written < (int)sizeof(image_path) && replacement_written > 0 && replacement_written < (int)sizeof(replacement_path) && - runtime_test_copy_executable("/bin/cat", image_path) && - runtime_test_copy_executable("/bin/echo", replacement_path); + runtime_test_copy_self_image(image_path); + + FILE *replacement_file = setup ? cbm_fopen(replacement_path, "wb") : NULL; + bool replacement_written_ok = + replacement_file && fputs("cbm-posix-replacement-image", replacement_file) >= 0; + if (replacement_file) { + replacement_written_ok = fclose(replacement_file) == 0 && replacement_written_ok; + } + setup = setup && replacement_written_ok; char original[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] = {0}; char replacement[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] = {0}; diff --git a/tests/test_main.c b/tests/test_main.c index 2d57f5468..6c23050ea 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -503,9 +503,19 @@ static int tf_maybe_run_runtime_image_holder(int argc, char **argv) { Sleep(INFINITE); return 25; #else - (void)argc; - (void)argv; - return -1; + /* POSIX copied-image holder: block reading stdin until the parent closes + * the release pipe, exactly like the cat(1) donor this replaced. A system + * utility cannot serve as the copied image — a multi-call coreutils + * binary (uutils cat) refuses to execute under the copied name. */ + if (argc != 2 || strcmp(argv[1], "__cbm_runtime_image_holder") != 0) { + return -1; + } + char release[16]; + ssize_t count; + do { + count = read(STDIN_FILENO, release, sizeof(release)); + } while (count > 0 || (count < 0 && errno == EINTR)); + return count == 0 ? 0 : 25; #endif }