NAME
Opcode - Disable named opcodes when compiling perl code
SYNOPSIS
use Opcode;
DESCRIPTION
Perl code is always compiled into an internal format before execution. Evaluating perl code (e.g. via "eval" or "do 'file'") causes the code to be compiled into an internal format and then, provided there was no error in the compilation, executed. The internal format is based on many distinct opcodes. By default no opmask is in effect and any code can be compiled.The Opcode module allow you to define an operator mask to be in effect
when perl next compiles any code. Attempting to compile code which contains a masked opcode will cause the compilation to fail with an error. The code will not be executed. NNOOTTEEThe Opcode module is not usually used directly. See the ops pragma and
Safe modules for more typical uses. WWAARRNNIINNGGThe authors make nnoo wwaarrrraannttyy, implied or otherwise, about the suitabil-
ity of this software for safety or security purposes. The authors shall not in any case be liable for special, incidental, consequential, indirect or other similar damages arising from the use of this software. Your mileage will vary. If in any doubt ddoo nnoott uussee iitt. OOppeerraattoorr NNaammeess aanndd OOppeerraattoorr LLiissttss The canonical list of operator names is the contents of the array PLopname defined and initialised in file opcode.h of the Perl source distribution (and installed into the perl library). Each operator has both a terse name (its opname) and a more verbose or recognisable descriptive name. The opdesc function can be used to return a list of descriptions for a list of operators. Many of the functions and methods listed below take a list of operators as parameters. Most operator lists can be made up of several types of element. Each element can be one of an operator name (opname)Operator names are typically small lowercase words like enter-
loop, leaveloop, last, next, redo etc. Sometimes they are rather cryptic like gv2cv, incmp and ftsvtx. an operator tag name (optag)Operator tags can be used to refer to groups (or sets) of oper-
ators. Tag names always begin with a colon. The Opcode module
defines several optags and the user can define others using the defineoptag function. a negated opname or optag An opname or optag can be prefixed with an exclamation mark, e.g., !mkdir. Negating an opname or optag means remove the corresponding ops from the accumulated set of ops at that point. an operator set (opset) An opset as a binary string of approximately 44 bytes which holds a set or zero or more operators. The opset and opsettoops functions can be used to convert from a list of operators to an opset and vice versa. Wherever a list of operators can be given you can use one or more opsets. See also Manipulating Opsets below. OOppccooddee FFuunnccttiioonnssThe Opcode package contains functions for manipulating operator names
tags and sets. All are available for export by the package. opcodes In a scalar context opcodes returns the number of opcodes inthis version of perl (around 350 for perl-5.7.0).
In a list context it returns a list of all the operator names. (Not yet implemented, use @names = opsettoops(fullopset).) opset (OP, ...) Returns an opset containing the listed operators. opsettoops (OPSET)Returns a list of operator names corresponding to those opera-
tors in the set. opsettohex (OPSET) Returns a string representation of an opset. Can be handy for debugging. fullopset Returns an opset which includes all operators. emptyopset Returns an opset which contains no operators. invertopset (OPSET) Returns an opset which is the inverse set of the one supplied. verifyopset (OPSET, ...) Returns true if the supplied opset looks like a valid opset (is the right length etc) otherwise it returns false. If an optional second parameter is true then verifyopset will croak on an invalid opset instead of returning false.Most of the other Opcode functions call verifyopset automati-
cally and will croak if given an invalid opset. defineoptag (OPTAG, OPSET) Define OPTAG as a symbolic name for OPSET. Optag names always start with a colon ":". The optag name used must not be defined already (defineoptag will croak if it is already defined). Optag names are global to the perl process and optag definitions cannot be altered or deleted once defined.It is strongly recommended that applications using Opcode
should use a leading capital letter on their tag names sincelowercase names are reserved for use by the Opcode module. If
using Opcode within a module you should prefix your tags names
with the name of your module to ensure uniqueness and thus avoid clashes with other modules. opmaskadd (OPSET) Adds the supplied opset to the current opmask. Note that there is currently no mechanism for unmasking ops once they have been masked. This is intentional. opmask Returns an opset corresponding to the current opmask. opdesc (OP, ...)This takes a list of operator names and returns the correspond-
ing list of operator descriptions. opdump (PAT)Dumps to STDOUT a two column list of op names and op descrip-
tions. If an optional pattern is given then only lines which match the (case insensitive) pattern will be output. It's designed to be used as a handy command line utility:perl -MOpcode=opdump -e opdump
perl -MOpcode=opdump -e 'opdump Eval'
MMaanniippuullaattiinngg OOppsseettss Opsets may be manipulated using the perl bit vector operators & (and), | (or), ^ (xor) and ~ (negate/invert). However you should never rely on the numerical position of any opcode within the opset. In other words both sides of a bit vector operatorshould be opsets returned from Opcode functions.
Also, since the number of opcodes in your current version of perl might not be an exact multiple of eight, there may be unused bits in the lastbyte of an upset. This should not cause any problems (Opcode functions
ignore those extra bits) but it does mean that using the ~ operator will typically not produce the same 'physical' opset 'string' as the invertopset function. TTOO DDOO ((mmaayybbee))$bool = opseteq($opset1, $opset2) true if opsets are logically eqiv
$yes = opsetcan($opset, @ops) true if $opset has all @ops set
@diff = opsetdiff($opset1, $opset2) => ('foo', '!bar', ...)
PPrreeddeeffiinneedd OOppccooddee TTaaggss :basecore null stub scalar pushmark wantarray const defined undef rv2sv sassign rv2av aassign aelem aelemfast aslice av2arylen rv2hv helem hslice each values keys exists delete preinc ipreinc predec ipredec postinc ipostinc postdec ipostdec int hex oct abs pow multiply imultiply divide idivide modulo imodulo add iadd subtract isubtract leftshift rightshift bitand bitxor bitor negate inegate not complement lt ilt gt igt le ile ge ige eq ieq ne ine ncmp incmp slt sgt sle sge seq sne scmp substr vec stringify study pos length index rindex ord chr ucfirst lcfirst uc lc quotemeta trans chop schop chomp schomp match split qr list lslice splice push pop shift unshift reverse condexpr flip flop andassign orassign and or xor warn die lineseq nextstate scope enter leave setstate rv2cv anoncode prototypeentersub leavesub leavesublv return method methodnamed - XXX loops via recursion?
leaveeval - needed for Safe to operate, is safe without entereval
:basemem These memory related ops are not included in :basecore becausethey can easily be used to implement a resource attack (e.g., con-
sume all available memory). concat repeat join range anonlist anonhash Note that despite the existence of this optag a memory resource attack may still be possible using only :basecore ops.Disabling these ops is a very heavy handed way to attempt to pre-
vent a memory resource attack. It's probable that a specific mem-
ory limit mechanism will be added to perl in the near future. :baseloop These loop ops are not included in :basecore because they can easily be used to implement a resource attack (e.g., consume all available CPU time). grepstart grepwhile mapstart mapwhile enteriter iter enterloop leaveloop unstack last next redo goto :baseio These ops enable filehandle (rather than filename) based input andoutput. These are safe on the assumption that only pre-existing
filehandles are available for use. To create new filehandles other ops such as open would need to be enabled. readline rcatline getc read formline enterwrite leavewrite print sysread syswrite send recv eof tell seek sysseek readdir telldir seekdir rewinddir :baseorig These are a hotchpotch of opcodes still waiting to be considered gvsv gv gelem padsv padav padhv padany rv2gv refgen srefgen refbless - could be used to change ownership of objects (reblessing)
pushre regcmaybe regcreset regcomp subst substcontsprintf prtf - can core dump
crypt tie untie dbmopen dbmclose sselect select pipeop sockpair getppid getpgrp setpgrp getpriority setpriority localtime gmtimeentertry leavetry - can be used to 'hide' fatal errors
custom - where should this go
:basemath These ops are not included in :basecore because of the risk of them being used to generate floating point exceptions (which wouldhave to be caught using a $SIG{FPE} handler).
atan2 sin cos exp log sqrt These ops are not included in :basecore because they have an effect beyond the scope of the compartment. rand srand :basethreadThese ops are related to multi-threading.
lock threadsv :defaultA handy tag name for a reasonable default set of ops. (The cur-
rent ops allowed are unstable while development continues. It will change.) :basecore :basemem :baseloop :baseio :baseorig :basethread If safety matters to you (and why else would you be using theOpcode module?) then you should not rely on the definition of
this, or indeed any other, optag! :filesysread stat lstat readlink ftatime ftblk ftchr ftctime ftdir fteexec fteowned fteread ftewrite ftfile ftis ftlink ftmtime ftpipe ftrexec ftrowned ftrread ftsgid ftsize ftsock ftsuid fttty ftzero ftrwrite ftsvtx fttext ftbinary fileno :sysdbghbyname ghbyaddr ghostent shostent ehostent - hosts
gnbyname gnbyaddr gnetent snetent enetent - networks
gpbyname gpbynumber gprotoent sprotoent eprotoent - protocols
gsbyname gsbyport gservent sservent eservent - services
gpwnam gpwuid gpwent spwent epwent getlogin - users
ggrnam ggrgid ggrent sgrent egrent - groups
:browse A handy tag name for a reasonable default set of ops beyond the :default optag. Like :default (and indeed all the other optags) its current definition is unstable while development continues. It will change. The :browse tag represents the next step beyond :default. It it a superset of the :default ops and adds :filesysread the :sysdb. The intent being that scripts can access more (possibly sensitive) information about your system but not be able to change it. :default :filesysread :sysdb :filesysopen sysopen open close umask binmodeopendir closedir - other dir ops are in :baseio
:filesyswrite link unlink rename symlink truncate mkdir rmdir utime chmod chownfcntl - not strictly filesys related, but possibly as dangerous?
:subprocess backtick system fork wait waitpidglob - access to Cshell via <`rm *`>
:ownprocess exec exit killtime tms - could be used for timing attacks (paranoid?)
:others This tag holds groups of assorted specialist opcodes that don't warrant having optags defined for them. SystemV Interprocess Communications: msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite :stilltobedecided chdir flock ioctl socket getpeername ssockopt bind connect listen accept shutdown gsockopt getsocknamesleep alarm - changes global timer state and signal handling
sort - assorted problems including core dumps
tied - can be used to access object implementing a tie
pack unpack - can be used to create/use memory pointers
entereval - can be used to hide code from initial compile
require dofilecaller - get info about calling environment and args
resetdbstate - perl -d version of nextstate(ment) opcode
:dangerous This tag is simply a bucket for opcodes that are unlikely to be used via a tag name but need to be tagged for completeness and documentation. syscall dump chrootSEE ALSO
ops(3) - perl pragma interface to Opcode module.
Safe(3) - Opcode and namespace limited execution compartments
AUTHORSOriginally designed and implemented by Malcolm Beattie, mbeat-
tie@sable.ox.ac.uk as part of Safe version 1. Split out from Safe module version 1, named opcode tags and other changes added by Tim Bunce.perl v5.8.8 2001-09-21 Opcode(3pm)