tcdrain() on socket yields EFAULT (expected EINVAL/ENOTTY)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Linux |
Fix Released
|
Medium
|
|||
linux-source-2.6.15 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
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(
/* printf(
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(
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://
*/
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.
Changed in linux: | |
status: | Unknown → Fix Released |
Changed in linux: | |
importance: | Unknown → Medium |
Thank you for you bug. You opened that bug on gnome-applets though, which might not be the best place for that tcdrain() problem you are mentionning. What sort of reply to you expect for it? Is gnome-applets using that API incorrectly?