Bug 816366

Summary: fclose crashes instead of returning an error
Product: [Fedora] Fedora Reporter: John Wendel <john.wendel>
Component: glibcAssignee: Jeff Law <law>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 16CC: fweimer, jakub, law, schwab
Target Milestone: ---   
Target Release: ---   
Hardware: athlon   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-04-25 21:58:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description John Wendel 2012-04-25 21:42:39 UTC
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):

2.14.90-24.fc16.6

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 21:58:28 UTC
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.