Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 597793 - fileno (NULL) segfaults instead of return -1 and set errno to EBADF
Summary: fileno (NULL) segfaults instead of return -1 and set errno to EBADF
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: rawhide
Hardware: All
OS: Linux
low
high
Target Milestone: ---
Assignee: Andreas Schwab
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 597794
TreeView+ depends on / blocked
 
Reported: 2010-05-30 14:33 UTC by Jan F. Chadima
Modified: 2010-05-31 11:48 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 597794 (view as bug list)
Environment:
Last Closed: 2010-05-31 11:25:18 UTC


Attachments (Terms of Use)

Description Jan F. Chadima 2010-05-30 14:33:56 UTC
Description of problem:
the function fileno crash the program, if called with NULL parameter
according to the documentation it should return -1 and set errno

Version-Release number of selected component (if applicable):
glibc-2.12.90-1.i686

How reproducible:
alvays

Steps to Reproduce:
compille and run:
#include <stdio.h>

int
main()
{
printf ("%d\n", fileno (NULL));
}
  
Actual results:
SIGSEGV

Expected results:
-1

Comment 1 Andreas Schwab 2010-05-31 08:32:12 UTC
NULL is not a pointer to a stream.

Comment 2 Jan F. Chadima 2010-05-31 10:41:23 UTC
NULL is the valid return value of fopen &tc.. so NULL can be considered as pointer to unopened stream.

Comment 3 Andreas Schwab 2010-05-31 10:52:26 UTC
NULL is not a pointer to a stream.

Comment 4 Jan F. Chadima 2010-05-31 11:10:51 UTC
from fileno man page:

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.)

Comment 6 Jakub Jelinek 2010-05-31 11:31:25 UTC
Note that EBADF in this case is a MAY FAIL rather than MUST FAIL, so while fileno could return -1/EBADF in that case, it doesn't have to.  And slowing the function down to cope with broken callers isn't a good idea.

Comment 7 Andreas Schwab 2010-05-31 11:48:14 UTC
That is irrelevant since NULL is not a pointer to a stream.


Note You need to log in before you can comment on or make changes to this bug.