From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 17 20:21:16 2014 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 650C0764 for ; Thu, 17 Jul 2014 20:21:16 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4BBD92DC5 for ; Thu, 17 Jul 2014 20:21:16 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.8/8.14.8) with ESMTP id s6HKLG93006575 for ; Thu, 17 Jul 2014 20:21:16 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 191931] New: isatty(-1)/ttyname_r(-1, ...) sets EBADF instead of ENOTTY; does not conform to manpage/POSIX Date: Thu, 17 Jul 2014 20:21:16 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: yaneurabeya@gmail.com X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2014 20:21:16 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191931 Bug ID: 191931 Summary: isatty(-1)/ttyname_r(-1, ...) sets EBADF instead of ENOTTY; does not conform to manpage/POSIX Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: Needs Triage Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: yaneurabeya@gmail.com The manpage for isatty/ttyname_r on FreeBSD and the OpenGroup site says that isatty/ttyname_r should return false/-1 and set ENOTTY if the file descriptor provided is invalid. The problem is that the glue code in libc doesn't convert the errno retrieved from tcgetattr properly in lib/libc/gen/isatty.c (which subsequently gets used in lib/libc/gen/ttyname.c), so the errno raised is actually EBADF. This issue was found by the NetBSD libc ATF testcases. Example: % cat /root/test_isatty_negative_one.c #include #include #include int main(void) { assert(!isatty(-1)); assert(errno == ENOTTY); return (0); } % /root/test_isatty_negative_one Assertion failed: (errno == ENOTTY), function main, file /root/test_isatty_negative_one.c, line 10. Abort trap (core dumped) [root@freebsd-10-x64 /scratch/tools]# truss /root/test_isatty_negative_one mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366140416 (0x80061b000) issetugid(0x80081b240,0x7fffffffefc1,0x40,0x0,0xffff80080081c27f,0x0) = 0 (0x0) lstat("/etc",{ mode=drwxr-xr-x ,inode=3129984,size=2560,blksize=32768 }) = 0 (0x0) lstat("/etc/libmap.conf",{ mode=-rw-r--r-- ,inode=3130403,size=47,blksize=32768 }) = 0 (0x0) open("/etc/libmap.conf",O_CLOEXEC,01760) = 3 (0x3) fstat(3,{ mode=-rw-r--r-- ,inode=3130403,size=47,blksize=32768 }) = 0 (0x0) mmap(0x0,47,PROT_READ,MAP_PRIVATE,3,0x0) = 34366173184 (0x800623000) close(3) = 0 (0x0) lstat("/usr",{ mode=drwxr-xr-x ,inode=1364352,size=512,blksize=32768 }) = 0 (0x0) lstat("/usr/local",{ mode=drwxr-xr-x ,inode=1364363,size=512,blksize=32768 }) = 0 (0x0) lstat("/usr/local/etc",{ mode=drwxr-xr-x ,inode=1453098,size=512,blksize=32768 }) = 0 (0x0) lstat("/usr/local/etc/libmap.d",0x7fffffffc738) ERR#2 'No such file or directory' munmap(0x800623000,47) = 0 (0x0) open("/var/run/ld-elf.so.hints",O_CLOEXEC,030360000) = 3 (0x3) read(3,"Ehnt\^A\0\0\0\M^@\0\0\0j\0\0\0\0"...,128) = 128 (0x80) lseek(3,0x80,SEEK_SET) = 128 (0x80) read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,106) = 106 (0x6a) close(3) = 0 (0x0) access("/lib/libc.so.7",0) = 0 (0x0) open("/lib/libc.so.7",O_CLOEXEC,030373770) = 3 (0x3) fstat(3,{ mode=-r--r--r-- ,inode=722308,size=1486376,blksize=32768 }) = 0 (0x0) mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34366173184 (0x800623000) mmap(0x0,3751936,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) = 34368241664 (0x80081c000) mmap(0x80081c000,1441792,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE|MAP_PREFAULT_READ,3,0x0) = 34368241664 (0x80081c000) mmap(0x800b7c000,45056,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0x160000) = 34371780608 (0x800b7c000) mmap(0x800b87000,167936,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34371825664 (0x800b87000) munmap(0x800623000,4096) = 0 (0x0) close(3) = 0 (0x0) munmap(0x800622000,4096) = 0 (0x0) mmap(0x0,102400,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366169088 (0x800622000) sysarch(0x81,0x7fffffffe118,0x4,0x0,0xffffffffffab8090,0x8080808080808080) = 0 (0x0) sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0) readlink("/etc/malloc.conf",0x7fffffffd840,1024) ERR#2 'No such file or directory' issetugid(0x800955e3e,0x7fffffffd840,0xffffffffffffffff,0x2,0x39,0xffffffff0fffffff) = 0 (0x0) mmap(0x0,4194304,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34371993600 (0x800bb0000) munmap(0x800bb0000,4194304) = 0 (0x0) mmap(0x0,8384512,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34371993600 (0x800bb0000) munmap(0x800bb0000,327680) = 0 (0x0) munmap(0x801000000,3862528) = 0 (0x0) sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0) sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0) ioctl(-1,TIOCGETA,0xffffead0) ERR#9 'Bad file descriptor' Assertion failed: (errno == ENOTTY), function main, file /root/test_isatty_negative_one.c, line 10. write(2,"Assertion failed: (errno == ENOT"...,100) = 100 (0x64) sigprocmask(SIG_SETMASK,SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGTRAP|SIGEMT|SIGFPE|SIGKILL|SIGBUS|SIGSEGV|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0) getpid() = 92137 (0x167e9) kill(92137,SIGABRT) = 0 (0x0) SIGNAL 6 (SIGABRT) process exit, rval = 0 -- You are receiving this mail because: You are the assignee for the bug.