php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20186 Segmentation fault (11) in recursive function call
Submitted: 2002-10-31 03:50 UTC Modified: 2002-11-16 01:11 UTC
From: john at alamak dot com dot sg Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 4.2.2 OS: FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-10-31 03:50 UTC] john at alamak dot com dot sg
I get this all the time when I include a recursive function call. I've tried rewriting the function several ways and get intermitten Segmentation faults, saw a SuSe Linux report about scripts terminating with similar output in the web server error_log.

I"ve tried just opening the fh and going down recursive directories with this, got the seg faults often.This version
buffers the file names in an array, closes the directory handle then processes the array, to count certain types of files in the directory tree. Still segfaults often enough to make it unreliable. I turned on the autoflush in php.ini and it dies in this routine.

FreeBSD 4.5-RELEASE
Apache/1.3.26 (Unix) PHP/4.2.2 mod_ssl/2.8.9 OpenSSL/0.9.6g
RegisterGlobals = On  :)

I use a perl script for my apache coplilation, here's my php_config line.

--with-mysql=/usr/local --with-gd=/usr/local --with-jpeg-dir=/usr/local/lib  --with-png-dir=/usr/
local/lib --with-zlib-dir=/usr/lib $xpm --with-freetype-dir=/usr/local/lib --with-mcrypt=/usr/local --with-gettext --wit
h-xml --with-zlib=/usr --with-bz2=/usr/local  --with-zip=/usr/local --with-mm=/usr/local --with-apache=../$apache --enable-ftp --disable-debug --enable-track-vars

Here's the current version of the function

function CountFiles($dir,$d) {
  global $home;
  global $prod_count;
  $farray = array(); $d++;
  if (is_dir("$home$dir")) {
    print "<!-- ISDIR dir=$dir level=$d -->\n";
    if ($dfh = @opendir("$home$dir")) {
	while (($fil = readdir($dfh)) !== false) {
		if (!preg_match("/^\.+$/", $fil)) {
			array_push($farray,"$fil");
		}
	}
	closedir($dfh);
	if (count($farray) > 0) {
	  while (list ($key, $file) = each ($farray)) {	
	    if (is_dir("$home$dir/$file")) {
		CountFiles("$dir/$file",$d);
		flush();
	    } else if (preg_match("/^thumb_\w+\.|\.wav$|\.aif$/", $file)) {
		$prod_count++;
		print "<!-- POST dir=$dir/$file prod_count=$prod_count -->\n";
		flush();
	    }
	}
      }
    }
  }
  flush();
}

It's not entirely reproducible, but once I got a directory where it causes the segfault I can comment out this routine and it's okay, comment it back and reload and it segfaults.
So in that sense it's reproducible. Restarting the web server has no effect. Though if I reload enough times sometimes the script completes, there is definitely some sort of bug, maybe the filehandle or array declaration isn't local or leaks out, not sure.

Hope it's not something stupid I overlooked. :)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-31 03:57 UTC] john at alamak dot com dot sg
Sorry, might help to mention that I did try the function first without using globals and returning the directory file_count and adding it up and returning the total, also had the same problem.
 [2002-10-31 09:05 UTC] yohgaki@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

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.

Please try it with CVS version.
 [2002-11-16 01:11 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC