This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/13253] New: fileno(3) crashes when passed NULL argument
- From: "klimes at centrum dot cz" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Tue, 04 Oct 2011 13:57:48 +0000
- Subject: [Bug libc/13253] New: fileno(3) crashes when passed NULL argument
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=13253
Bug #: 13253
Summary: fileno(3) crashes when passed NULL argument
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper.fsp@gmail.com
ReportedBy: klimes@centrum.cz
Classification: Unclassified
fileno() crashes when passed NULL, e.g. due to these construct:
fileno(fopen("no-existent", "r");
http://pubs.opengroup.org/onlinepubs/009695399/functions/fileno.html says:
...Otherwise, the value -1 shall be returned and errno set to indicate the
error...
man 3 fileno says:
ERRORS
These functions should not fail and do not set the external variable
errno. (However, in case fileno() detects that its argument is not a valid
stream, it must return -1 and set errno to EBADF.)
I think it should rather detect the invalid argument and return -1 with errno
set to EBADF as docs suggest.
Looking into source it is evident that CHECK_FILE (fp, EOF); macro call in
fileno() doesn't check the stream (is no-operation). That's just done for cases
when compiled with IO_DEBUG, which is not defined in production. The
CHECK_FILE macro should always check validity of the passed fp parameter.
Moreover 'EOF' in the macro call should be replaced with -1 as it is the error
return value.
Referenced files:
libio/libioP.h
libio/fileno.c
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.