summaryrefslogtreecommitdiff
path: root/src/mkfifo.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-12-19 18:16:07 +0000
committerJim Meyering <jim@meyering.net>2005-12-19 18:16:07 +0000
commit17f521adfdd3b415f68fc30b61eb115c1e379a79 (patch)
tree86ad24b847d7ac6891a23ecdfd177f43828ce27b /src/mkfifo.c
parente0029290b895661e32bb17ef714fb14321c15bcf (diff)
downloadcoreutils-17f521adfdd3b415f68fc30b61eb115c1e379a79.tar.xz
(main) Avoid a minor race condition when `-m MODE' is specified, by using
open, fchown, and close rather than just chown. To do that reliably (even with an overly restrictive umask), ensure that each mknod/mkfifo call uses a mode including at least owner-read access.
Diffstat (limited to 'src/mkfifo.c')
-rw-r--r--src/mkfifo.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mkfifo.c b/src/mkfifo.c
index baed853f8..d31412b05 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include "system.h"
+#include "chmod-safer.h"
#include "error.h"
#include "modechange.h"
#include "quote.h"
@@ -75,6 +76,7 @@ int
main (int argc, char **argv)
{
mode_t newmode;
+ mode_t tmp_mode;
const char *specified_mode;
int exit_status = EXIT_SUCCESS;
int optc;
@@ -122,9 +124,14 @@ main (int argc, char **argv)
free (change);
}
+ /* This is the mode we'll use in the mknod or mkfifo call.
+ If it doesn't include S_IRUSR, use S_IRUSR so the final
+ open-for-fchmod will succeed. */
+ tmp_mode = (newmode & S_IRUSR) ? newmode : S_IRUSR;
+
for (; optind < argc; ++optind)
{
- int fail = mkfifo (argv[optind], newmode);
+ int fail = mkfifo (argv[optind], tmp_mode);
if (fail)
error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
@@ -133,7 +140,7 @@ main (int argc, char **argv)
if (fail == 0 && specified_mode)
{
- fail = chmod (argv[optind], newmode);
+ fail = chmod_safer (argv[optind], newmode, 0, S_IFIFO);
if (fail)
error (0, errno, _("cannot set permissions of fifo %s"),
quote (argv[optind]));