This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/10784] New: expect fails when calling ttyname on a serial port
- From: "jaredtsmith at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 15 Oct 2009 16:47:52 -0000
- Subject: [Bug libc/10784] New: expect fails when calling ttyname on a serial port
- Reply-to: sourceware-bugzilla at sourceware dot org
With the file:
glibc-2.9/sysdeps/unix/sysv/linux/ttyname.c
I found that it can get failures in getttyname it has the variable
getttyname_name that is re-used where it allocates a big enough chunk of
memory and then re-uses it the problem is that it doesn't re-copy dev into the
variable if it changes so you can end up in a situation with expect where the
tty changes from /dev/ttys0 --> /dev/pts/1 however the way the code is written
it will append 1 into /dev/ttys0 since it doesn't copy in /dev/pts as it
should. This causes it to return null and crash in expect.
Here is the patch I created for the issue:
diff -ruN glibc-2.9/sysdeps/unix/sysv/linux/ttyname.c glibc-2.9-
fixed/sysdeps/unix/sysv/linux/ttyname.c
--- glibc-2.9/sysdeps/unix/sysv/linux/ttyname.c 2006-12-05 15:25:29.000000000 -
0600
+++ glibc-2.9-fixed/sysdeps/unix/sysv/linux/ttyname.c 2009-10-15
10:12:20.000000000 -0500
@@ -79,7 +79,21 @@
return NULL;
}
*((char *) __mempcpy (getttyname_name, dev, devlen - 1)) = '/';
- }
+ }else{
+ // Need to copy dev string into the buffer. The
+ // variable is a static so it carries the value between
+ // calls and there are situations where the tty can change
+ // for example when running expect on a serial line it will
+ // switch from /dev/ttys0 --> /dev/pty/x without this fix
+ // expect will fail on a serial line as it ends up turning
+ // /dev/ttys0 --> /dev/ttysx which is not valid causing it
+ // to return a null value and fail.
+ memcpy(getttyname_name, dev, devlen); //copy the string
plus the null terminator
+ // The memcpy call following this to copy in d->d_name
expects a trailing "/" to
+ // be appended without that it will be off by one
+ getttyname_name[devlen-1]='/'; //append the
trailing "/"
+ getttyname_name[devlen]='\0'; //NULL terminate the
string
+ }
memcpy (&getttyname_name[devlen], d->d_name, dlen);
if (__xstat64 (_STAT_VER, getttyname_name, &st) == 0
#ifdef _STATBUF_ST_RDEV
--
Summary: expect fails when calling ttyname on a serial port
Product: glibc
Version: 2.9
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: jaredtsmith at gmail dot com
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=10784
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.