Bug 816366 - fclose crashes instead of returning an error
Summary: fclose crashes instead of returning an error
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 16
Hardware: athlon
OS: Linux
unspecified
urgent
Target Milestone: ---
Assignee: Jeff Law
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-04-25 21:42 UTC by John Wendel
Modified: 2016-11-24 16:05 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-04-25 21:58:28 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

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.


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