Bug 816366 - fclose crashes instead of returning an error
fclose crashes instead of returning an error
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
athlon Linux
unspecified Severity urgent
: ---
: ---
Assigned To: Jeff Law
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2012-04-25 17:42 EDT by John Wendel
Modified: 2016-11-24 11:05 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2012-04-25 17:58:28 EDT
Type: Bug
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 John Wendel 2012-04-25 17:42:39 EDT
Description of problem:

File "POO" does not exist

#include <stdio.h>
int main ( int argc, char **argv ) {
    FILE *foo;
    foo = fopen ( "POO", "r" );
    fclose ( foo );
    return 0;

Version-Release number of selected component (if applicable):


How reproducible:

100 %

Steps to Reproduce:
1. Run the program listed above.
2. See the segmentation fault
3. Be sad.
Actual results:

Segmentation fault

Expected results:

Error EBADF returned

Additional info:
Comment 1 Jeff Law 2012-04-25 17:58:28 EDT
GLIBC's behaviour is valid according to ISO C standard 7.1.4.

"If an argument to a function has an invalid value (such as a value outside the domain of the function, or a pointer outside the address space of the program, or a null pointer... the behaviour is undefined".  The rationale behind this is it's generally impossible to determine if a particular pointer value is a valid pointer and points to memory of the correct data type.

Clearly you need to be checking the result of your fopen call to ensure it's non-null.

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