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

2001-02-07 Thread Boian Bonev

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 100) 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.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-02-06 Thread Boian Bonev

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.

b.

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 07, 2001 12:31 AM
Subject: [PHP-DEV] PHP 4.0 Bug #9136 Updated: simple script with infinite
function calls causes seg fault


> ID: 9136
> Updated by: waldschrott
> Reported By: [EMAIL PROTECTED]
> Status: Closed
> Bug Type: Reproduceable crash
> Assigned To: waldschrott
> Comments:
>
> and guess this "bug" was present in any version before, what
> do you expect to happen here? you will never leave these
> function calls (as you know I guess), as far as your stack
> is full it is full
>
> remember php has to remember each and every function call it
> did...
>
> a()
>b()
>   a()
>  b()
>
>
> if you really need exactly this construct, I would suggest
> you to use a static variable to count the total function
> calls and find the critical values a specific system
> segfaults (with your original code), then you stick a
> for(;;) around it and implement a check (eg. in a()) against
> the static variable to leave the recursion if a value with
> enough distance to the critical value is reached, then you
> should be able to begin the recursion again
>
> any recursion can be displayed as a loop, do not use
> recursion if you want to recurse infinitely
>
> Previous Comments:
> --
-
>
> [2001-02-06 17:22:36] [EMAIL PROTECTED]
> PHP doesn't handle infinite recursion, and as earlier was discussed on the
php-dev list, it wont be implemented to guard for this, because of the high
performance impact.
>
> --
-
>
> [2001-02-06 17:18:03] [EMAIL PROTECTED]
> ---
> <%
>
> function a () {
> b();
> }
>
> function b () {
> a();
> }
>
> a();
>
> %>
>
> done
> -
>
> The simple script above causes a seg fault.  If you need more info on
configuration etc please mail me.  We made this simple example from a more
compilcated instance.  This bug was also present in 4.0.3pl1, we upgraded to
try and stop the seg fault...
>
> thanks!
>
> --
-
>
>
>
> ATTENTION! Do NOT reply to this email!
> To reply, use the web interface found at
http://bugs.php.net/?id=9136&edit=2
>
>
> --
> PHP Development Mailing List 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-02-06 Thread André Langhorst

> why didn't you make it a Feature Request then? But I suppose you tried,
> and wasn't be able to do that. Jani, is this a bug in the bugsystem?

I did! it was just put into a rhetorical question ;)

andré

-- 
· André Langhorst   · t: +49 571 3201801 ·
· [EMAIL PROTECTED]   · m: +49 173 9558736 ·
· PHP Quality Assurance · http://qa.php.net  ·


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]