nalika / rpms / bash

Forked from rpms/bash 2 years ago
Clone

Blame SOURCES/bash-4.3-pipefd-leak.patch

07a490
diff --git a/execute_cmd.c b/execute_cmd.c
07a490
--- a/execute_cmd.c
07a490
+++ b/execute_cmd.c
07a490
@@ -536,6 +536,10 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
07a490
   REDIRECT *my_undo_list, *exec_undo_list;
07a490
   volatile int last_pid;
07a490
   volatile int save_line_number;
07a490
+#if defined (PROCESS_SUBSTITUTION)
07a490
+  volatile int ofifo, nfifo, osize, saved_fifo;
07a490
+  volatile char *ofifo_list = NULL;
07a490
+#endif
07a490
 
07a490
 #if 0
07a490
   if (command == 0 || breaking || continuing || read_but_dont_execute)
07a490
@@ -681,6 +685,17 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
07a490
   if (shell_control_structure (command->type) && command->redirects)
07a490
     stdin_redir = stdin_redirects (command->redirects);
07a490
 
07a490
+#if defined (PROCESS_SUBSTITUTION)
07a490
+  if (variable_context != 0)
07a490
+    {
07a490
+      ofifo = num_fifos ();
07a490
+      ofifo_list = copy_fifo_list ((int*)&osize);
07a490
+      saved_fifo = 1;
07a490
+    }
07a490
+  else
07a490
+    saved_fifo = 0;
07a490
+#endif
07a490
+
07a490
   /* Handle WHILE FOR CASE etc. with redirections.  (Also '&' input
07a490
      redirection.)  */
07a490
   if (do_redirections (command->redirects, RX_ACTIVE|RX_UNDOABLE) != 0)
07a490
@@ -688,6 +703,9 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
07a490
       cleanup_redirects (redirection_undo_list);
07a490
       redirection_undo_list = (REDIRECT *)NULL;
07a490
       dispose_exec_redirects ();
07a490
+#if defined (PROCESS_SUBSTITUTION)
07a490
+      free ((void*)ofifo_list);
07a490
+#endif
07a490
       return (last_command_exit_value = EXECUTION_FAILURE);
07a490
     }
07a490
 
07a490
@@ -982,6 +1000,17 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
07a490
   if (my_undo_list || exec_undo_list)
07a490
     discard_unwind_frame ("loop_redirections");
07a490
 
07a490
+#if defined (PROCESS_SUBSTITUTION)
07a490
+  if (saved_fifo)
07a490
+    {
07a490
+      nfifo = num_fifos ();
07a490
+      if (nfifo > ofifo)
07a490
+       close_new_fifos ((char*)ofifo_list, osize);
07a490
+      free ((void*)ofifo_list);
07a490
+    }
07a490
+#endif
07a490
+
07a490
+
07a490
   /* Invert the return value if we have to */
07a490
   if (invert)
07a490
     exec_result = (exec_result == EXECUTION_SUCCESS)