Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

NULL in IF statement secure mode

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
m-lee
Smarty Rookie


Joined: 17 Mar 2004
Posts: 31

PostPosted: Thu Dec 13, 2007 10:10 pm    Post subject: NULL in IF statement secure mode Reply with quote

Hi,

is there any possibility how i can say that NULL is allowed in
security_settings ['IF_FUNCS'] ?

Currently im getting this error:
Code:

Fatal error: Smarty error: [in list.inc line 29]: syntax error: (secure mode) 'NULL' not allowed in if statement (Smarty_Compiler.class.php, line 1385) in F:\intranet\htdocs\myproject\lib\smarty\Smarty.class.php on line 1095


For a statement like this:
Code:

{if $MYARRAY[j][i].name != NULL}


I know i could use an other syntax but i dont want to to this due to several reasons.
One is that i have a few hundert templates using this syntax Smile

Also an other question:
Is there the possibility to disable {php}{/php} but allow all other things in
security_settings ? Again i have the problem of the very huge template set which make a lot of use of modifiers / funcs / constants etc.
And if i have to scan all thoose templates im gooing to be lazy.

Or any way to get all modifiers / funcs / constants used in all templates without watching them all manualy? Any idea? Smile

Or blacklisting insteed of whitelisting.
I know this is not a good idea due to security related aspects but may be helpfull in some cases.

Thanks for your help!
Back to top
View user's profile Send private message
m-lee
Smarty Rookie


Joined: 17 Mar 2004
Posts: 31

PostPosted: Thu Dec 13, 2007 10:46 pm    Post subject: Reply with quote

Well i made a prefilter now to get rid of the
{php} tags
maybe someone else needs this too:
Code:

function removePHPTagsFromTemplate($tplContent, &$smarty)
{

    $toReplace      = array('{php}','{/php}');
    $replaceWIth    = array('{ldelim}php{rdelim}', '{ldelim}/php{rdelim}');
   
    $tplContent = str_ireplace($toReplace, $replaceWIth, $tplContent);
    return ($tplContent);
}

And then register it
Code:

$Smarty->register_prefilter('removePHPTagsFromTemplate');


But that is not the solution im happy with Sad
And still i cant activate security due to the NULL problem and the other reasons mentioned above.

Well i just wanted to post this prefilter. Would be nice if someone can awnser my questions from the previous thread.

Thank you and regards!
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Fri Dec 14, 2007 12:02 am    Post subject: Reply with quote

Have you tried adding 'NULL' to $security_settings['IF_FUNCS']?
After a quick glance at the Smarty_Compiler.class.php file that should do the trick. What version of Smarty do you use btw? In my version (2.6.1Cool that syntax error gets thrown in line 1396, not in line 1385 as it is stated in your error message.

If adding 'NULL' to the array doesn't help I guess the only way to deal with it would be a prefilter. Either the one you posted yourself to remove the {php} Tags without need for $security or some filter that rewrites all your
Code:
{if $variable == NULL}
to
Code:
{if is_empty($variable)}
or something similar.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
m-lee
Smarty Rookie


Joined: 17 Mar 2004
Posts: 31

PostPosted: Fri Dec 14, 2007 2:08 am    Post subject: Reply with quote

Celeb wrote:
Have you tried adding 'NULL' to $security_settings['IF_FUNCS']?


Yes i tried this without success. Even tried in constants etc. Sad

Celeb wrote:

After a quick glance at the Smarty_Compiler.class.php file that should do the trick. What version of Smarty do you use btw? In my version (2.6.1Cool that syntax error gets thrown in line 1396, not in line 1385 as it is stated in your error message.

The latest i just added some not important lines.

Celeb wrote:

or some filter that rewrites all your
Code:
{if $variable == NULL}
to
Code:
{if is_empty($variable)}
or something similar.


That must be a very powerfull reg expression. I doubt this will work for all cases Sad
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Fri Dec 14, 2007 2:29 am    Post subject: Reply with quote

Well when you already started editing Smarty files you could just add
Code:
case 'null':

right after
Code:
case '*':
case '/':
case '@':


This must be lowercase, since it gets strtolowered in the switch().

About the regex .. http://xkcd.com/208/ Wink
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
m-lee
Smarty Rookie


Joined: 17 Mar 2004
Posts: 31

PostPosted: Fri Dec 21, 2007 6:43 pm    Post subject: Reply with quote

well i did not edited any kogic in the files and wont do so.

Anyhow any other ideas? Is this maybe a feature smarty is missing?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Dec 22, 2007 1:07 am    Post subject: Reply with quote

Have you tried using null (lowercase) instead of NULL? Smarty is case-sensitive and the permitted intrinsic tokens are defined in the compiler as the following literals: true, false, yes, no, on, off, null.

So the error you are getting is actually due to the fact that Smarty sees your NULL as a function name rather than seeing it as the token null that you intended. Or so I suppose Smile

It seems to me that this is perhaps not documented well in the manual. Hmmm.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP