Package: expect
Version: 5.43.0-8build1

I tried to use in a chroot without /proc mounted and it dumped core.
Debugging it revealed that it uses the `ttyname' library call without
checking whether it worked.

The attached patch arranges that in this situation expect will print
an error message to stderr and exit nonzero, rather than coredumping.

This is not ideal but the code structure didn't seem to permit another
easy answer (the error handling in this area is generally not very
good I think) and this situation is (I think) supposed only to happen
in very pathological situations so I think bombing out is less
unacceptable.

Regards,
Ian.

--- expect-5.43.0/pty_termios.c~        2004-05-07 17:46:03.000000000 +0100
+++ expect-5.43.0/pty_termios.c 2007-09-04 11:14:09.000000000 +0100
@@ -366,6 +366,17 @@
 #define W_OK 02
 #endif
 
+static int ttyname_checked(int fd) {
+       const char *result;
+       result= ttyname(fd);
+       if (!result) {
+               perror("expect: pty_termios: system configuration problem:"
+                      " ttyname() failed");
+               exit(-1);
+       }
+       return result;
+}
+
 int
 exp_getptymaster()
 {
@@ -451,7 +462,7 @@
        master = open("/dev/ptc",O_RDWR);
        if (master >= 0) {
                /* never fails */
-               slave_name = ttyname(master);
+               slave_name = ttyname_checked(master);
        }
        exp_pty_slave_name = slave_name;
        return(master);
@@ -472,7 +483,7 @@
                close(slave);
                return -1;
        }
-       strcpy(slave_name, ttyname(slave));
+       strcpy(slave_name, ttyname_checked(slave));
        exp_pty_slave_name = slave_name;
        close(slave);
        return master;


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to