This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/11538] New: invalid use of errno after calling ttyname_r
- From: "bruno at clisp dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 25 Apr 2010 20:12:15 -0000
- Subject: [Bug libc/11538] New: invalid use of errno after calling ttyname_r
- Reply-to: sourceware-bugzilla at sourceware dot org
ttyname_r is specified in POSIX
<http://www.opengroup.org/onlinepubs/9699919799/functions/ttyname.html>.
The return value is specified like this:
"If successful, the ttyname_r() function shall return zero.
Otherwise, an error number shall be returned to indicate the error."
This means, ttyname_r should return the error number. Whether it
additionally stores it in errno, is not specified. And indeed,
the two implementations in glibc/sysdeps/posix/ttyname_r.c and
glibc/sysdeps/unix/sysv/linux/ttyname_r.c can fail, returning
ENOTTY, without setting errno to ENOTTY. (Look at the end of the
function getttyname_r: If it cannot find the tty, it sets errno to
its previous value ('save') and returns ENOTTY. When all calls to
getttyname_r end like this, __ttyname_r returns ENOTTY without
assigning errno.)
Therefore, callers of ttyname_r should not use the value of errno
after the call failed, but instead use the return value from ttyname_r.
Find attached a fix.
--
Summary: invalid use of errno after calling ttyname_r
Product: glibc
Version: 2.11
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: bruno at clisp dot org
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://sourceware.org/bugzilla/show_bug.cgi?id=11538
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.