Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 597793 - fileno (NULL) segfaults instead of return -1 and set errno to EBADF
fileno (NULL) segfaults instead of return -1 and set errno to EBADF
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
All Linux
low Severity high
: ---
: ---
Assigned To: Andreas Schwab
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks: 597794
  Show dependency treegraph
Reported: 2010-05-30 10:33 EDT by Jan F. Chadima
Modified: 2010-05-31 07:48 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 597794 (view as bug list)
Last Closed: 2010-05-31 07:25:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Jan F. Chadima 2010-05-30 10:33:56 EDT
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):

How reproducible:

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

printf ("%d\n", fileno (NULL));
Actual results:

Expected results:
Comment 1 Andreas Schwab 2010-05-31 04:32:12 EDT
NULL is not a pointer to a stream.
Comment 2 Jan F. Chadima 2010-05-31 06:41:23 EDT
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 06:52:26 EDT
NULL is not a pointer to a stream.
Comment 4 Jan F. Chadima 2010-05-31 07:10:51 EDT
from fileno man page:

       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 07:31:25 EDT
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 07:48:14 EDT
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.