Grisha Levit <[email protected]> writes:
> The meaning of non-file permission umask bits is implementation defined.
> On Bionic libc, attempting to set them triggers a FORTIFY runtime check.
>
> * src/nohup.c: (main) Avoid setting non-permission bits in umask, just
> clear the bits we need to use.
> ---
> On Android:
>
> $ nohup true
> FORTIFY: umask: called with invalid mask -601
> Aborted nohup true
>
> See
> https://android.googlesource.com/platform/bionic/+/refs/heads/ndk-r29-release/libc/bionic/fortify.cpp#400
>
> src/nohup.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/nohup.c b/src/nohup.c
> index d58fcc53f..933bd02ba 100644
> --- a/src/nohup.c
> +++ b/src/nohup.c
> @@ -141,7 +141,8 @@ 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);
> + umask (umask_value & ~mode);
> out_fd = (redirecting_stdout
> ? fd_reopen (STDOUT_FILENO, file, flags, mode)
> : open (file, flags, mode));
Interesting, thanks for the report. Can't we just do the following to
avoid the extra umask() call?
diff --git a/src/nohup.c b/src/nohup.c
index d58fcc53f..8a4c1a034 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 (~mode & (S_IRWXU | S_IRWXG | S_IRWXO));
out_fd = (redirecting_stdout
? fd_reopen (STDOUT_FILENO, file, flags, mode)
: open (file, flags, mode));
The Linux man pages state that the other bits are ignored, so I really
wish Bionic would behave the same way instead of killing the program...
Collin