Re: PHP 4.0 Bug #9136 Updated: simple script with infinite function calls causes seg fault

From: Date: Wed, 07 Feb 2001 16:22:40 +0000
Subject: Re: PHP 4.0 Bug #9136 Updated: simple script with infinite function calls causes seg fault
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-45958@lists.php.net to get a copy of this message
hi, > > indeed it is theoretically impossible to track this :) > > > > implement a recursive alrorithm for something e.g.: > > > > function foo($n) { // calc $n! > > if ($n<=1) > > return $n; > > else > > return foo($n-1)*$n; > > } > > > > now tell me if it is infinite or finite? ;-) this is a verification and > > cannot be solved runtime. > > > > the best thing that can be done is to set a stack limit (php function call > > level) to something reasonable and thus avoid the segfault. > > This gives a problem itself, how many levels before the stack is full? Not > every function call has the same memory footprint, so you can't tell after > how many levels the stack is full. of course. but it is better to set something like 1000(or 1000000) and be sure that a malicious user cannot exploit it. as far as i remember php local vars are emalloc-ed and are not on the stack. so there is an average value like 64(or 640) bytes per stack frame or something... b.

« previous php.dev (#45958) next »