php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18218 fclose crashes PHP and Apache
Submitted: 2002-07-08 03:59 UTC Modified: 2002-07-09 04:59 UTC
From: ray at unreal64 dot net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.2.1 OS: Windows NT4.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ray at unreal64 dot net
New email:
PHP Version: OS:

 

 [2002-07-08 03:59 UTC] ray at unreal64 dot net
Hi !

We are using OpenBSD as server-side OS, and Windoze for testing. I found a problem, which can be a bug. If not, or someone allready reported (I didn't find), I am sorry. This bug accurs only at Windoze - all works perfect under OpenBSD.

I have code (pseudo):

fopen(file1,"r")
if (fopen(file2,"r")) {
    stat(file1);
    stat(file2);

    // check timestamp
    if (stat1 VS stat2) {
        
        read(file2) into array (restore cache);

        close(file1);
        close(file2);
        return;
    }

    close(file2);
}

// rebuild cache
read(file1);
close(file1);             

process file1 data

// store cache
if (fopen(file3,"w+b")) {

    fwrite(file3,serialize(...));

    fclose(file3);  /****** HERE Apache/php CRASHES
}


File1 is 'source'. File2 is 'cache' - read only. I check last modify time,
if valid, then I read cache. If not, I process source, re-open cache
for writing and store datas.

At fclose process die.

If I remove fclose, all works fine (other file operations, DB access, etc.).
If I remove initiali fopen for cache and time checking (fstat), then fclose3
also works perfect.

My own opinion: openning files/stating them/closing causes PHP die.

Have a nice day,
Don't kill me :o)
Bye
Ray

There is original code (class function):


// read strings file
function cmdLngFile($fname) {

    $fnamec="../cache/".basename($fname);

    if (!file_exists($fname))
        stlc_exit("lng file $fname not found");

    $fd=@fopen($fname,"r");
    if (empty($fd))
        stlc_exit("can't read or empty lng $fname");
    $fdc=@fopen($fnamec,"rb");
    if (!empty($fdc)) {

        $statn=fstat($fd);
        $statc=fstat($fdc);

        // use cache
        if ($statn[9]<=$statc[9]) {

            $cache=fread($fdc,filesize($fnamec));

            $this->lngs=array_merge($this->lngs,unserialize($cache));
            fclose($fd);
            fclose($fdc);

            return;
        }

        // need rebuild cache...
        fclose($fdc);
    }

    $lng=fread($fd,filesize($fname));
    fclose($fd);

    // process file contents
    $lnglen=strlen($lng);
    ...
    nothing interested here, jsut process language file and
    setup array $this->lngs in form array["language_id"] => "text"

    // store cache
    $fdcw=@fopen($fnamec,"w+b");
    if (!empty($fdcw)) {

        $cache=serialize($this->lngs);
        fwrite($fdcw,$cache);
        fflush($fdcw);

        //!!!! PHP bug (?) - this falldown apache on windoze, BSD works
        // keep comment for windoze
        //fclose($fdcw);
    }
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-08 05:47 UTC] sander@php.net
Reclassified.
 [2002-07-08 08:21 UTC] ray at unreal64 dot net
Sorry for choosing bad cathegory initially.

R.
 [2002-07-08 21:40 UTC] sniper@php.net
Can you please try this snapshot:

http://snaps.php.net/win32/php4-win32-latest.zip

Some resource problems were fixed..

 [2002-07-09 04:59 UTC] ray at unreal64 dot net
I downloaded new version and:

1. fclose no more fall down php
2. php fall down randomly - after 4-5 refresh with access violation for address 0x000000

So, php still crashes, but on different place. I weren't abble to determine where exactly it fall down. But it is DIFFERENT bug, so, I think we can close the thread..

Without compiling PHP I can't say where it fall down (scripts are too long). In all cases, my code no more produces crash.

If you are interested let me know, I can compile PHP and find where exactly PHP touch NULL (MSC 6).

Have a  nice day,
R.
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 05:03:45 2023 UTC