Re: [hackers] [sbase] [PATCH] mkfifo: Simplify -m handling
Thanks for looking this over.
On 2019-06-13, Richard Ipsum <richardipsum_AT_fastmail.co.uk> wrote:
> I might be wrong but I think this will cause a subtle change in
> behaviour since the umask is needed to correctly interpret the mode
> string. One example that's documented in chmod(1p) is "-w" vs "a-w".
> "a-w" removes all write perms, but "-w" removes only the permissions
> that weren't filtered by the mask. This could explain why this
> is currently being done in two separate steps.
umask(0) sets the mask to 0 and returns the old mask, so I think the
mode is interpreted the same way before and after this change
(getumask() is even implemented as two calls to umask, returning the
result of the first call).
Since chmod isn't affected by the current umask, I think the final
mode is the same before and after this change.
$ umask 022
$ ./mkfifo.old -m -w testfifo && ls -l testfifo && rm testfifo
pr--rw-rw- 1 michael michael 0 Jun 13 17:02 testfifo
$ ./mkfifo.new -m -w testfifo && ls -l testfifo && rm testfifo
pr--rw-rw- 1 michael michael 0 Jun 13 17:02 testfifo
$ ./mkfifo.old -m a-w testfifo && ls -l testfifo && rm testfifo
pr--r--r-- 1 michael michael 0 Jun 13 17:03 testfifo
$ ./mkfifo.new -m a-w testfifo && ls -l testfifo && rm testfifo
pr--r--r-- 1 michael michael 0 Jun 13 17:03 testfifo
> That being said looking at mkfifo(1p) it says that if -m is present
> then the value of mkfifo's mode argument is unspecified, but it
> shouldn't be any less restrictive than the argument provided to -m.
> So if I'm reading this correctly the current argument of
> (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
> isn't strictly correct either since it could be less restrictive
> than the argument provided to -m.
Yes, so I think the patch also prevents this issue since the FIFO is
created with the final mode.
> If I'm not mistaken in the second part then maybe the mode argument
> to mkfifo should be 0, then apply the actual mode using chmod?
I think this would work as well.
Received on Fri Jun 14 2019 - 02:27:37 CEST
This archive was generated by hypermail 2.3.0
: Fri Jun 14 2019 - 02:36:24 CEST