RE: [PHP-DEV] Re: PHP 4.0 Bug #7080 Updated: Recursive Include()s crash system

From: Date: Wed, 11 Oct 2000 06:22:25 +0000
Subject: RE: [PHP-DEV] Re: PHP 4.0 Bug #7080 Updated: Recursive Include()s crash system
Groups: php.dev 
Request: Send a blank email to php-dev+get-34636@lists.php.net to get a copy of this message
Potentially, couldn't this also occur in C/C++ itself? Even if they DO have a way of stopping this with inbuilt functionality, good programming practice usually dictates that they do something like having a #DEFINE statement that will only allow that include file being imported once. In C/C++ this would look like: #IFNDEF __MY_INC_FILE__ #DEFINE __MY_INC_FILE__ /* Have your code here */ ... #ENDIF __MY_INC_FILE__ I would suggest you do something like this in PHP: /////////////////////////////////////////////////// TESTINC.INC file: <?php /* This is the TESTINC.INC file */ /* Test if the include file exists */ if(!$_DEFINE_TESTINC_INC_) { /* Set the define so we don't include this again */ $_DEFINE_TESTINC_INC_ = TRUE; echo "Hit!!<BR>\n"; } /* End of _DEFINE_TESTINC_INC_ */ ?> /////////////////////////////////////////////////// /////////////////////////////////////////////////// TESTINC.PHP file: <?php /* This is the MAIN file TESTINC.PHP */ /* Count the number of Hits! to see how many times this include file is included */ for($i=0;$i<20;$i++) { echo "Count: $i<BR>\n"; include("testinc.inc"); } ?> /////////////////////////////////////////////////// NOTE: Variables set in the include file will exist even outside of it. This is how you stop it from happening again. Sure, the potential pitfall is still there (although as mentioned the resource limit in the php.ini file is useful). I would personally be against a recursive limit, but if you wanted to only include a file X amount of times why not have $_DEFINE_TESTINC_INC_ simply increment itself each time you enter the include file and test if it reaches a certain maximum number? At least you have more control over it then... Mike Berry-Porter mikebp@alverstone.com.au -----Original Message----- From: Andi Gutmans [mailto:andi@zend.com] Sent: Wednesday, 11 October 2000 1:16 PM To: Harold Paulson; Bug Database Subject: Re: [PHP-DEV] Re: PHP 4.0 Bug #7080 Updated: Recusive Include()s crash system Under Windows PHP handles stack overflows. UNIX is an older operating system and doesn't give you anyway that I know of to really cope and recover from stack overflows. We have discussed putting a limit on recursive include()'s in the past but it would mean adding code and an arbitrary limit (which would be quite meaningless) to the execution function. Andi At 05:00 PM 10/10/00 -0700, Harold Paulson wrote: >Hi, > >I just wanted to follow up on this a bit.. > >Your first point is quite correct. I have indeed set resource limits for >apache (and every other daemon I'm running). The limits that were set by >default on my box were infinite. Yes, it is my fault that I didn't know >this and fix it beforehand, but how often is it the case? How many of the >web servers out there are set up similarly? Most of them, I would >suspect, have this defect, since it's the default in at least FreeBSD and >RedHat. This is their problem, and I think they should fix it, but we >must admit that it is the status quo of the web today. > > >In reference to your second suggestion, include_once() is neat, I'll start >using it, but...I can't be the only sysadmin who isn't the sole developer >on his server? > >I think PHP would be a more stable tool if maybe it featured an >'include_limit' directive in php.ini, or somesuch. I can imagine >situations where a developer might want to include a file more than once, >but...more than a thousand times? > >Thanks for your time. > > - H > > > >On 10 Oct 2000, Bug Database wrote: > > > ID: 7080 > > Updated by: stas > > Reported By: haroldp@internal.org > > Status: Closed > > Bug Type: Reproduceable crash > > Assigned To: > > Comments: > > > > First of all, you probably need to use resource limits. Second, you > have include_once for this - use it. > > > > Previous Comments: > > --------------------------------------------------------------------------- > > > > [2000-10-07 20:36:26] haroldp@internal.org > > Include()ing a file that Include()s itself - ie, a recusive > > Include() - will completely crash a system. Not just the > > web server, it ran my box out of swap in a few seconds > > and required a power cycle. > > > > Could we get some sanity checking on this? I had a > > web designer's *typo* bring a ssytem to its knees. > > > > > > > > --------------------------------------------------------------------------- > > > > > > Full Bug description available at: > > http://bugs.php.net/?id=7080 > > > > > > >-- >PHP Development Mailing List <http://www.php.net/> >To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net >For additional commands, e-mail: php-dev-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net --- Andi Gutmans <andi@zend.com> http://www.zend.com/ -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#34636) next »