]> granicus.if.org Git - sudo/commitdiff
In dispatch_signal() for stopped processes check for tcgetpgrp()
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 May 2016 20:13:44 +0000 (14:13 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 May 2016 20:13:44 +0000 (14:13 -0600)
returning -1.  Also change checks from "saved_pgrp != -1" to
"fd != -1".  Coverity CID 104098.

src/exec.c

index e10a567ab7e06c64ff54525ffaffd73524d31aef..f38128606686cd6c2e3883e94303fc33a7b6b754 100644 (file)
@@ -565,6 +565,12 @@ dispatch_signal(struct sudo_event_base *evbase, pid_t child,
                int fd = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0);
                if (fd != -1) {
                    saved_pgrp = tcgetpgrp(fd);
+                   if (saved_pgrp == -1) {
+                       close(fd);
+                       fd = -1;
+                   }
+               }
+               if (saved_pgrp != -1) {
                    /*
                     * Child was stopped trying to access controlling
                     * terminal.  If the child has a different pgrp
@@ -605,7 +611,7 @@ dispatch_signal(struct sudo_event_base *evbase, pid_t child,
                            SIGTSTP);
                    }
                }
-               if (fd != -1) {
+               if (saved_pgrp != -1) {
                    /*
                     * Restore command's process group if different.
                     * Otherwise, we cannot resume some shells.