php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49338 when fopen is used without the second parameter, php segfaults in apache 2.2
Submitted: 2009-08-23 16:17 UTC Modified: 2009-08-31 01:00 UTC
From: ttessier at swhistlesoft dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2.10 OS: solaris 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ttessier at swhistlesoft dot com
New email:
PHP Version: OS:

 

 [2009-08-23 16:17 UTC] ttessier at swhistlesoft dot com
Description:
------------
When fopen is used without the second parameter, php segfaults in apache 2.2. I had this happen two times, once when I was using bcompiler and once when I was using xml_parser. I thought that the issue was the other modules until I realized that I was missing the second parameter to fopen. 

I was doing a test on the returned value to check for validity such as if ( $fh ) or if ( is_resource ( $fh ) ) and was unable to see any warnings.

Once I removed the test and any interior blocks to the filehandle test from the code, I was able to see a warning. I fixed the issue and have been working solid since. 

Reproduce code:
---------------
$regionf = 'regions.xml' ;
$fregions = fopen ( $regionf ) ;
if ( $fregions ){
    echo "File Opened" ;
    $xmldoc = fread ( $fregions, filesize ( $regionf ) ) ;
    $parser = xml_parser_create  ( ) ;
    if ( $parser ){
	xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING, "UTF-8");
       xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); 
       xml_parse ( $parser, $doc ) ;
       xml_parse_into_struct($parser, trim($xmldoc), $xml_values);
       print_r ( $xml_values ) ;
       xml_parser_free ( $parser ) ;
    }
    fclose ( $fregions ) ;
}

Expected result:
----------------
apache segfault -  browser displays previous content ( cache )


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-23 16:23 UTC] scottmac@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.


 [2009-08-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC