dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
ea821e
From 756f8301d5f7959312bea3fa8865bb543d43fd50 Mon Sep 17 00:00:00 2001
ea821e
From: Karel Zak <kzak@redhat.com>
ea821e
Date: Wed, 8 Feb 2017 10:19:56 +0100
ea821e
Subject: [PATCH] su: properly clear child PID
ea821e
ea821e
Upstream: http://github.com/karelzak/util-linux/commit/dffab154d29a288aa171ff50263ecc8f2e14a891
ea821e
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1419474
ea821e
Signed-off-by: Karel Zak <kzak@redhat.com>
ea821e
---
ea821e
 login-utils/su-common.c | 25 +++++++++++++++----------
ea821e
 1 file changed, 15 insertions(+), 10 deletions(-)
ea821e
ea821e
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
ea821e
index d53d690..9b3cad5 100644
ea821e
--- a/login-utils/su-common.c
ea821e
+++ b/login-utils/su-common.c
ea821e
@@ -357,21 +357,26 @@ create_watching_parent (void)
ea821e
 	    break;
ea821e
 	}
ea821e
       if (pid != (pid_t)-1)
ea821e
-	if (WIFSIGNALED (status))
ea821e
-	  {
ea821e
-            fprintf (stderr, "%s%s\n", strsignal (WTERMSIG (status)),
ea821e
-                     WCOREDUMP (status) ? _(" (core dumped)") : "");
ea821e
-            status = WTERMSIG (status) + 128;
ea821e
-	  }
ea821e
-	else
ea821e
-	  status = WEXITSTATUS (status);
ea821e
+	{
ea821e
+	  if (WIFSIGNALED (status))
ea821e
+	    {
ea821e
+	      fprintf (stderr, "%s%s\n", strsignal (WTERMSIG (status)),
ea821e
+                       WCOREDUMP (status) ? _(" (core dumped)") : "");
ea821e
+	      status = WTERMSIG (status) + 128;
ea821e
+	    }
ea821e
+	  else
ea821e
+	    status = WEXITSTATUS (status);
ea821e
+
ea821e
+          /* child is gone, don't use the PID anymore */
ea821e
+          child = (pid_t) -1;
ea821e
+	}
ea821e
       else
ea821e
 	status = 1;
ea821e
     }
ea821e
   else
ea821e
     status = 1;
ea821e
 
ea821e
-  if (caught_signal)
ea821e
+  if (caught_signal && child != (pid_t)-1)
ea821e
     {
ea821e
       fprintf (stderr, _("\nSession terminated, killing shell..."));
ea821e
       kill (child, SIGTERM);
ea821e
@@ -379,7 +384,7 @@ create_watching_parent (void)
ea821e
 
ea821e
   cleanup_pam (PAM_SUCCESS);
ea821e
 
ea821e
-  if (caught_signal)
ea821e
+  if (caught_signal && (child != (pid_t)-1))
ea821e
     {
ea821e
       sleep (2);
ea821e
       kill (child, SIGKILL);
ea821e
-- 
ea821e
2.7.4
ea821e