From 7416d88eea64525c361f97c30e6b309f109929e0 Mon Sep 17 00:00:00 2001 From: brad Date: Tue, 16 Jan 2001 22:29:27 +0000 Subject: [PATCH] fix symlink race. based mostly on patch from the FreeBSD ports tree. -- Reviewed by: beck@ --- shells/bash/patches/patch-execute_cmd.c | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 shells/bash/patches/patch-execute_cmd.c diff --git a/shells/bash/patches/patch-execute_cmd.c b/shells/bash/patches/patch-execute_cmd.c new file mode 100644 index 00000000000..476d379285e --- /dev/null +++ b/shells/bash/patches/patch-execute_cmd.c @@ -0,0 +1,33 @@ +--- execute_cmd.c.orig Thu Jun 8 11:29:00 1995 ++++ execute_cmd.c Tue Jan 16 16:30:39 2001 +@@ -2714,10 +2714,11 @@ + { + WORD_DESC *redirectee = redirect->redirectee.filename; + int redir_fd = redirect->redirectee.dest; +- int fd, redirector = redirect->redirector; ++ int fd = -1, redirector = redirect->redirector; + char *redirectee_word; + enum r_instruction ri = redirect->instruction; + REDIRECT *new_redirect; ++ mode_t um; + + if (ri == r_duplicating_input_word || ri == r_duplicating_output_word) + { +@@ -2938,11 +2939,14 @@ + pid_t pid = getpid (); + + /* Make the filename for the temp file. */ +- sprintf (filename, "/tmp/t%d-sh", pid); ++ sprintf (filename, "/tmp/t-sh-XXXXXX", pid); + +- fd = open (filename, O_TRUNC | O_WRONLY | O_CREAT, 0666); +- if (fd < 0) ++ fd = mkstemp (filename); ++ if (fd != -1) + return (errno); ++ um = umask (022); ++ umask (um); ++ fchmod (fd, 0666 & ~um); + + errno = 0; /* XXX */ + if (redirectee->word)