]> git.armaanb.net Git - opendoas.git/blobdiff - pam.c
libopenbsd/closefrom: correctly handle snprintf truncation
[opendoas.git] / pam.c
diff --git a/pam.c b/pam.c
index ec89d047dcc73bee6fe62ae991d11c82177d9af9..3e8fab5946020f9604dc5e218321ce369a67bb75 100644 (file)
--- a/pam.c
+++ b/pam.c
@@ -149,7 +149,7 @@ watchsession(pid_t child)
 {
        sigset_t sigs;
        struct sigaction act, oldact;
-       int status;
+       int status = 1;
 
        /* block signals */
        sigfillset(&sigs);
@@ -191,7 +191,7 @@ watchsession(pid_t child)
                status = 1;
 
 close:
-       if (caught_signal) {
+       if (caught_signal && child != (pid_t)-1) {
                fprintf(stderr, "\nSession terminated, killing shell\n");
                kill(child, SIGTERM);
        }
@@ -199,10 +199,12 @@ close:
        pamcleanup(PAM_SUCCESS);
 
        if (caught_signal) {
-               /* kill child */
-               sleep(2);
-               kill(child, SIGKILL);
-               fprintf(stderr, " ...killed.\n");
+               if (child != (pid_t)-1) {
+                       /* kill child */
+                       sleep(2);
+                       kill(child, SIGKILL);
+                       fprintf(stderr, " ...killed.\n");
+               }
 
                /* unblock cached signal and resend */
                sigaction(SIGTERM, &oldact, NULL);