diff --git a/NEWS b/NEWS index 283d8046d..392129dad 100644 --- a/NEWS +++ b/NEWS @@ -47,6 +47,10 @@ GNU coreutils NEWS -*- outline -*- with multi-byte thousands grouping characters. [This bug was present in "the beginning".] + 'nohup' avoids implementation defined behavior setting umask, + avoiding a FORTIFY runtime failure on Bionic libc. + [This bug was present in "the beginning".] + 'od --strings' with '-N' now works correctly. Previously od might write a NUL byte after a heap buffer, or output invalid addresses. [These bugs were present in "the beginning".] diff --git a/src/nohup.c b/src/nohup.c index d58fcc53f..6218986cb 100644 --- a/src/nohup.c +++ b/src/nohup.c @@ -141,7 +141,7 @@ main (int argc, char **argv) char const *file = "nohup.out"; int flags = O_CREAT | O_WRONLY | O_APPEND; mode_t mode = S_IRUSR | S_IWUSR; - mode_t umask_value = umask (~mode); + mode_t umask_value = umask (0); out_fd = (redirecting_stdout ? fd_reopen (STDOUT_FILENO, file, flags, mode) : open (file, flags, mode)); diff --git a/tests/misc/nohup.sh b/tests/misc/nohup.sh index 917d2a389..f49997f26 100755 --- a/tests/misc/nohup.sh +++ b/tests/misc/nohup.sh @@ -122,4 +122,24 @@ export POSIXLY_CORRECT=1 returns_ 127 nohup >/dev/null 2>&1 || fail=1 unset POSIXLY_CORRECT +# Make sure we create nohup.out with u+rw permissions +( + rm -f nohup.out + + # POSIX shells immediately exit the subshell on exec error. + # So check we can write to /dev/tty before the exec, which + # isn't possible if we've no controlling tty for example. + test -c /dev/tty && >/dev/tty || exit 0 + exec >/dev/tty + test -t 1 || exit 0 + + umask 600 # Ensure nohup undoes this + + nohup echo hi || fail=1 + test "$(stat -c %a nohup.out)" = 600 || fail=1 + + rm -f nohup.out + exit $fail +) || fail=1 + Exit $fail