[Bug 72200] tcdrain() on socket yields EFAULT (expected EINVAL/ENOTTY)
Jörg Höhle
Joerg-Cyril.Hoehle at T-Systems.com
Mon Nov 27 12:55:55 UTC 2006
Public bug reported:
tcdrain(3) returns EFAULT when invoked on a socket. EFAULT is a serious error meaning that the tcdrain()
function has passed to the kernel an invalid memory address.
Expected error values from passing a non-tty to tcdrain() are EINVAL,
ENOTTY (or possibly EOPNOTSUPP on Mac OSX, but we're talking about Linux
now).
Here's a program with test results for files, pipes, pty and sockets.
/* tcdrain(3) returns EFAULT (a serious error) on sockets */
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main () {
int i;
for (i=0; i<=2; i++) {
int retval, save;
errno = 0;
retval = tcdrain(i);
save = errno;
printf("tcdrain(%d)=(%d,%d)\n",i,retval,save);
/* printf("tcdrain(%d)=(%d,%d=%s)\n",i,retval,save,
save ? strerror(save) : ""); */
}
return 0;
}
/*
$ ~/Bugs/tcdrain
tcdrain(0)=(0,0)
tcdrain(1)=(0,0)
tcdrain(2)=(0,0)
$ ~/Bugs/tcdrain | cat
tcdrain(0)=(0,0)
tcdrain(1)=(-1,22) # EINVAL = Invalid argument
tcdrain(2)=(0,0)
$ ~/Bugs/tcdrain 2>/dev/null
tcdrain(0)=(0,0=)
tcdrain(1)=(0,0=)
tcdrain(2)=(-1,25) # ENOTTY = Inappropriate ioctl for device
$ echo foo | ~/Bugs/tcdrain
tcdrain(0)=(-1,22)
tcdrain(1)=(0,0)
tcdrain(2)=(0,0)
$ ~/Bugs/tcdrain <~/Bugs/tcdrain
tcdrain(0)=(-1,25=Inappropriate ioctl for device)
tcdrain(1)=(0,0=)
tcdrain(2)=(0,0=)
# Now I'd expect an error similar to the previous ones,
or possibly EOPNOTSUPP, but not EFAULT:
$ ssh localhost ~/Bugs/tcdrain
tcdrain(0)=(-1,14) # EFAULT = Bad address
tcdrain(1)=(-1,14) # EFAULT
tcdrain(2)=(-1,14) # EFAULT
$ ssh -t localhost ~/Bugs/tcdrain
tcdrain(0)=(0,0)
tcdrain(1)=(0,0)
tcdrain(2)=(0,0)
Connection to localhost closed.
$ uname -a # Dapper 6.06 Ubuntu Debian
Linux jchlaptop 2.6.15-27-686 #1 SMP PREEMPT Sat Sep 16 02:13:27 UTC 2006 i686 GNU/Linux
Reference:
http://sourceforge.net/tracker/index.php?func=detail&aid=1592343&group_id=1355&atid=101355
*/
ssh has nothing to do with the bug, but I don't know how to connect I/O
to a socket on the command line, short of writing a tiny program that
does socket() calls (and implement a tiny server). You will obtain the
same errno if you pass tcdrain such a socket fd, without intervening
ssh.
This is for sure a bug unrelated to Ubuntu. However the
bugzilla.kernel.org FAQ asks to contact the distribution first.
Regards,
Jörg Höhle.
** Affects: linux-meta (Ubuntu)
Importance: Undecided
Status: Unconfirmed
--
tcdrain() on socket yields EFAULT (expected EINVAL/ENOTTY)
https://launchpad.net/bugs/72200
More information about the kernel-bugs
mailing list