diff --git a/src/main/tools/linux-sandbox.c b/src/main/tools/linux-sandbox.c index 23bd024f1cffaf..ff75f057ba38a8 100644 --- a/src/main/tools/linux-sandbox.c +++ b/src/main/tools/linux-sandbox.c @@ -565,7 +565,7 @@ static void SetupDirectories() { perror("getpwuid(getuid())"); exit(EXIT_FAILURE); } else { - DIE("UID %d not found in passwd file", (int)getuid()); + DIE("UID %d not found in passwd file\n", (int)getuid()); } } char *homedir = uid_passwd->pw_dir; diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index 9e6bc857d8dcf6..5238c09f773fc1 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -434,6 +434,19 @@ EOF expect_log "Sandboxed execution failed, which may be legitimate" } +function test_sandbox_different_nobody_uid() { + cat /etc/passwd | sed 's/\(^nobody:[^:]*:\)[0-9]*:[0-9]*/\15000:16000/g' > \ + "${TEST_TMPDIR}/passwd" + unshare --user --mount --map-root-user -- bash - \ + << EOF || fail "Hermetic genrule with different UID for nobody failed" \ +set -e +set -u + +mount --bind ${TEST_TMPDIR}/passwd /etc/passwd +bazel build examples/genrule:works &> ${TEST_log} +EOF +} + # The test shouldn't fail if the environment doesn't support running it. check_supported_platform || exit 0 check_sandbox_allowed || exit 0