Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: A minilanguage with the least effort?

by jethro (Monsignor)
on Feb 17, 2009 at 15:57 UTC ( [id://744461]=note: print w/replies, xml ) Need Help??


in reply to A minilanguage with the least effort?

Anecdotal evidence: I wrote a sort of "miniperl" interpreter that I believed (or lets say hoped) to be secure by transforming and filtering the miniperl into executable perl and using eval to execute it. It operated upon a hierarchical set of hashes and was crippled down to essentially mathematical operations, strings, control structures and calling of functions I allowed or provided.

It was for a local management program for a play-by-mail space opera game, so security was not really necessary, just a bonus so that config files could be exchanged between player and game master without worries

A typical example of what it did:

#bi is population index planet 'Taurus I' : bi+= 200+10*3 : system.scoutdata='Heavily armed' system taurus : code { if ( scoutdata eq '' ) { owned=1 } } translated to: $planet{'taurus i'}{'bi'}+= 200+10*3; $planet{'system'}{'scoutdata'}= 'Heavily armed'; if ($system{'taurus'}{'scoutdata'} eq '') { $system{'taurus'}{'owned'} +=1; }

All the hashes were tied so that the %system-hash of a planet could be reached by simply saying system.something= .... This made it possible to do consitency checks or further actions when a variable was changed. Also if a variable like 'owned' was configured as hierarchical, not only was taurus.owned set to 1 in the example above but also the 'owned' of every planet in this system, i.e. 'taurus i'.owned would have been set too

As you can see I had to exclude most of the special characters from my language, especially all the sigils. Since arrays or hashes couldn't be specified directly, looping was only possible through function calls. No regex was possible

It was fun programming it, but you really have to cripple the language to put perl into a sandbox (and I still can't be completely sure I plugged all holes). While it fitted my needs in this case perfectly, I wouldn't really trust it on a public interface in the web for example

By the way, I used Parse::RecDescent for the parsing of the language (actually it was really two languages that were parsed)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://744461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found