]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 57967] Only set APPEND mode for regular files
authorPaul Smith <psmith@gnu.org>
Mon, 30 Mar 2020 18:38:47 +0000 (14:38 -0400)
committerPaul Smith <psmith@gnu.org>
Tue, 31 Mar 2020 04:19:20 +0000 (00:19 -0400)
APPEND is a permanent mode shared by all users of a file.  If we
set it on a tty, pipe, etc. it will stay in effect even after make
exits, which can cause problems.

Patch provided by 0xef967c36@gmail.com

* src/output.c (set_append_mode): Check for a regular file.

Copyright-paperwork-exempt: yes

src/output.c

index 4845f2027673e98dca22d7c0878ebc1544019476..e222e0a51443af4c626b478e41b7f350b54cfac1 100644 (file)
@@ -144,14 +144,18 @@ log_working_directory (int entering)
   return 1;
 }
 
-/* Set a file descriptor to be in O_APPEND mode.
-   If it fails, just ignore it.  */
+/* Set a file descriptor referring to a regular file
+   to be in O_APPEND mode.  If it fails, just ignore it.  */
 
 static void
 set_append_mode (int fd)
 {
 #if defined(F_GETFL) && defined(F_SETFL) && defined(O_APPEND)
-  int flags = fcntl (fd, F_GETFL, 0);
+  struct stat stbuf;
+  int flags;
+  if (fstat (fd, &stbuf) != 0 || !S_ISREG (stbuf.st_mode))
+    return;
+  flags = fcntl (fd, F_GETFL, 0);
   if (flags >= 0)
     {
       int r;