You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jochen Toppe <jo...@jtoee.com> on 2004/10/05 22:10:53 UTC

Re: RES: Question on recursion in macros

*snip*
> apparently works and the recursion in test macro works too, it causes a
> stack overflow
*snip*

Is there any way to limit the depth of the recursion (I can't find
anything)? StackOverflows are nasty especially if you let dumb users write
templates and they feel like they can crash you app.

#macro ( showInfo $p )
 Info: $p
 #showInfo($p)
#end
#showInfo("Test")

The same code also crashes in Intellij Idea when put in the file templates
(it used veloc) ;)

Cheers,
  Jochen




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: RES: Question on recursion in macros

Posted by Jochen Toppe <jo...@jtoee.com>.
Then you'll like this one too:

#set ($mem = "12345678901234567890123456789012345678901234567890")
#foreach ($link in [1..1000000]) $set ($mem = "$mem$mem") #end

This one leads "only" to an OutOfMem and is easily fixed by overloading
the getIterator of the Uberspector and limiting the number of times a loop
may be executed.

"Too few arguments to macro"? Strange, the code leads to a StackOverflow
each time I execute it.

Jochen


> Hmm... that's interesting.  I allow arbitrary users to upload Velocity
> web pages, so I'm a bit concerned.
>
> When I tried the macro in a page with my WebApp, it didn't crash my app,
> or generate a StackOverflow.  Instead it produced 2200 "Test Info", then
> stopped with an error message:
>
> VM #showInfo: error : too few arguments to macro. Wanted 1 got 0
>
>
> My memory usage also goes up by 5M each time I refresh the page.  I guess
>  this would cause me to run out of memory eventually if it wasn't gc'd.
> I'll
> have to play with this a bit more.
>
> WILL
>
>
>
> ----- Original Message -----
> From: "Jochen Toppe" <jo...@jtoee.com>
> To: <ve...@jakarta.apache.org>
> Sent: Tuesday, October 05, 2004 1:10 PM
> Subject: Re: RES: Question on recursion in macros
>
>
>
>>
>> *snip*
>>
>>> apparently works and the recursion in test macro works too, it causes
>>> a stack overflow
>> *snip*
>>
>>
>> Is there any way to limit the depth of the recursion (I can't find
>> anything)? StackOverflows are nasty especially if you let dumb users
>> write templates and they feel like they can crash you app.
>>
>> #macro ( showInfo $p )
>> Info: $p
>> #showInfo($p)
>> #end
>> #showInfo("Test")
>>
>>
>> The same code also crashes in Intellij Idea when put in the file
>> templates (it used veloc) ;)
>>
>>
>> Cheers,
>> Jochen
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: RES: Question on recursion in macros

Posted by Will Glass-Husain <wg...@forio.com>.
Hmm... that's interesting.  I allow arbitrary users to upload Velocity web 
pages, so I'm a bit concerned.

When I tried the macro in a page with my WebApp, it didn't crash my app, or 
generate a StackOverflow.  Instead it produced 2200 "Test Info", then 
stopped with an error message:

VM #showInfo: error : too few arguments to macro. Wanted 1 got 0

My memory usage also goes up by 5M each time I refresh the page.  I guess 
this would cause me to run out of memory eventually if it wasn't gc'd.  I'll 
have to play with this a bit more.

WILL


----- Original Message ----- 
From: "Jochen Toppe" <jo...@jtoee.com>
To: <ve...@jakarta.apache.org>
Sent: Tuesday, October 05, 2004 1:10 PM
Subject: Re: RES: Question on recursion in macros


>
> *snip*
>> apparently works and the recursion in test macro works too, it causes a
>> stack overflow
> *snip*
>
> Is there any way to limit the depth of the recursion (I can't find
> anything)? StackOverflows are nasty especially if you let dumb users write
> templates and they feel like they can crash you app.
>
> #macro ( showInfo $p )
> Info: $p
> #showInfo($p)
> #end
> #showInfo("Test")
>
> The same code also crashes in Intellij Idea when put in the file templates
> (it used veloc) ;)
>
> Cheers,
>  Jochen
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: RES: Question on recursion in macros

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jochen,

> *snip*
> > apparently works and the recursion in test macro works too, it causes a
> > stack overflow
> *snip*
> 
> Is there any way to limit the depth of the recursion (I can't find
> anything)? StackOverflows are nasty especially if you let dumb users write
> templates and they feel like they can crash you app.
I couldn't find anything, either.  Maybe a post in bugzilla might
help.  I'm sure many of us want that feature.  ;)

In the mean time, you can add a "depth" parameter to your macro and
increment it on recursion.  If depth comes to a certain point, stop
recursing.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org