[glib: 1/2] glib/gbacktrace.c: Handling properly the dup(stderr) call



commit 1e3b1eb1119eba7b99944a0c54db36da140df420
Author: Emmanuel Fleury <emmanuel fleury u-bordeaux fr>
Date:   Mon Aug 26 10:46:05 2019 +0200

    glib/gbacktrace.c: Handling properly the dup(stderr) call
    
    If the dup(stderr) returns '-1' (an error occured), then the program
    shouldn't call a 'close(stderr); dup(old_err);' after the exec() failed.
    
    Fix issue #1880

 glib/gbacktrace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/glib/gbacktrace.c b/glib/gbacktrace.c
index 34cb1ce46..3b3b0eacb 100644
--- a/glib/gbacktrace.c
+++ b/glib/gbacktrace.c
@@ -293,7 +293,8 @@ stack_trace (const char * const *args)
     {
       /* Save stderr for printing failure below */
       int old_err = dup (2);
-      fcntl (old_err, F_SETFD, fcntl (old_err, F_GETFD) | FD_CLOEXEC);
+      if (old_err != -1)
+        fcntl (old_err, F_SETFD, fcntl (old_err, F_GETFD) | FD_CLOEXEC);
 
       close (0); dup (in_fd[0]);   /* set the stdin to the in pipe */
       close (1); dup (out_fd[1]);  /* set the stdout to the out pipe */
@@ -302,7 +303,11 @@ stack_trace (const char * const *args)
       execvp (args[0], (char **) args);      /* exec gdb */
 
       /* Print failure to original stderr */
-      close (2); dup (old_err);
+      if (old_err != -1)
+        {
+          close (2);
+          dup (old_err);
+        }
       perror ("exec gdb failed");
       _exit (0);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]