|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-04-17 12:28 UTC] dominique at ottello dot net
Description:
------------
Execution of this code works fine with Apache 2.4.16 to 2.4.20 and PHP 5.3.29, 5.4.45, 5.5.30 or 7.0.5 but crash and restart Apache with PHP 5.6.15 to 5.6.20
AH00428: Parent: child process 5912 exited with status 255 -- Restarting.
All things otherwise identical, the problem occurs only with PHP 5.6.15 to 5.6.20. I have not tested with versions prior to 5.6.15.
Test script:
---------------
$c_vhostConfFile = 'myfile.conf';
//myfile.conf is a copy of:
//$c_vhostConfFile = 'j:/wamp/bin/apache/apache2.4.20/conf/extra/httpd-vhosts.conf';
$myVhostsContents = file_get_contents($c_vhostConfFile);
// ServerName to find
$server = "wampserver.aviatechno";
$p_value = preg_quote($server);
$mask = "{
<VirtualHost # beginning of VirtualHost
((?!</VirtualHost>).)* # avoid premature end
\n\s*ServerName\s+${p_value}\s*\n # Test server name
.*? # we stop as soon as possible
</VirtualHost>\s*\n # end of VirtualHost
}isx";
if(preg_match($mask, $myVhostsContents, $VirtualHost_match) !== false)
echo "<pre>".htmlspecialchars($VirtualHost_match[0])."</pre>\n";
else
echo "<p>preg_match error</p>\n";
?>
Expected result:
----------------
The whole content of the VirtualHost definition that is:
<VirtualHost *:80>
DocumentRoot "G:/www/wampserver"
ServerAdmin webmaster@ottello.net
ServerAlias www.wampserser.aviatechno
ServerName wampserver.aviatechno
<Directory "G:/www/wampserver/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>
Actual result:
--------------
Apache crash and restart. No error in php_error.log
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 04:00:01 2025 UTC |
Google says that exception code 0XC00000FD means stack overflow and the back trace also looks a lot like it. This may either be a bug in PCRE, or, which is much more likely, this is the standard stack overflow you tend to get with very inefficient regular expressions on large inputs. The reason why you're seeing the stack overflow only with Apache but not CLI is likely that they have different stack sizes configured (IIRC PHP CLI builds have a huge stack size). For your particular expression it is likely that the ((?!</VirtualHost>).)* triggers the pathological case. You should be able to avoid it either by splitting this up in two expressions (first match <VirtualHost>.*?</VirtualHost> and then match ServerName on the result) or by trying to rewrite it, e.g. using something like [^<]*(?:<(?!/VirtualHost)[^<]*)* ("unrolled loop" pattern).Hi, With the use of "unrolled loop" the regexp don't crash Apache anymore with PHP 5.6.x $mask = '{ <VirtualHost # beginning of VirtualHost [^<]*(?:<(?!/VirtualHost)[^<]*)* # avoid premature end \n\s*ServerName\s+'.$p_value.'\s*\n # Test server name .*? # we stop as soon as possible </VirtualHost>\s*\n # end of VirtualHost }isx';