svashisht / rpms / bash

Forked from rpms/bash 4 years ago
Clone

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

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