12

I discovered a way to make php segfault, and I'm a bit curious about what's happening. Maybe someone can explain this for me?

joern@xps:..com/trunk5/tools/nestedset> cat > while.php
<?php
while(1){
        die('dd');
}
?>
^C
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php   
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%    

As you can see, it doesn't happen every time. Php caching?

php5 5.2.10.dfsg.1-2ubuntu6.1
6
  • I can't reproduce this on 5.2.11 ... Commented Nov 19, 2009 at 13:41
  • Do you have valgrind available? Can you run it through valgrind i.e. valgrind php -f ./while.php and post the output? Commented Nov 19, 2009 at 13:42
  • 5
    I can't reproduce the error. My php version is the same as yours. Commented Nov 19, 2009 at 13:44
  • Funny, I was dealing with something very similar this morning... I had a cron running for the past 8 months that had been segfaulting recently. The script defined an array, looped over it, did nothing (because the 'enabled' key was set to false on each item in the array) and quit. It segfaults 1 out of 8 times it runs. Bizarre. I'm using 5.2.6-1+lenny. Does any other variation of the script segault? Commented Nov 19, 2009 at 13:54
  • valgrind output: while1.no/files/4.txt I'm not sure how to read this correctly, but it did not segfault right? I'f not, i'll try until it does Commented Nov 19, 2009 at 14:07

2 Answers 2

4

Wikipedia: Segmentation Fault

A little bit of research indicates that some PHP extensions may not play nice, or may not play nice with each other. It can also depend on the server, or the server configuration.

If you are using both XDebug and Zend Debugger loaded at the same time it can cause this.

At first I thought possibly the while loop used with a die() statement might be part of the cause.. I am curious to know if this also causes a segmentation error:

while (!$fault) { 
  $fault=check_fault_function();
  }
if ($fault) { die('dd'); }

If not it may be just how you are using while and die together. As you know while(1) {} is an infinite loop... (your server may not know how to allocate memory for infinite routines) so unless you are trying to cause crashes this is normally bad practice.

Sign up to request clarification or add additional context in comments.

4 Comments

in fact, I am using xdebug, didn't think of that.. I was not able to recreate the fault using valgrind, but i managed to get a core dump from just running "php - while.php" while1.no/files/core.tgz (fitting domain, don't you think?) I'll try your php script next :)
im not sure if the check_fault_function i created does what you need, but at least php cant guess the number of iterations: pastebin.org/56321 This code also segfaulted, but only 30% of time, just like the previous. core: while1.no/files/core2.tgz
if my example also segfaulted the error lies in the die() statement, not the while loop. possibly it is trying to unallocate memory/variables that are not there when it exits? bugs.php.net/bug.php?id=40045 describes how the "-r" conditional can create segfaults on die().. how about trying 'php while.php' instead of 'php -f while.php'?
I managed to get "php while.php" to segfault as well. Php's man says no parameter is the same as -f. I was wrong when i said i had xdebug installed, that was only in my php/apache conf (get_loaded_extensions() confirms), so it sounds right that its die() that's not behaving.
4

This appears to be related to a known bug in the PHP source. It's been fixed in the PHP trunk, and it looks like it was rolled out some time around the 5.2.11 release. See here and here for details.

1 Comment

I had this problem with 5.3.14 just now, and it was due to XDebug, as suggested by @Talvi Watja here: stackoverflow.com/a/1768821/125668

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.