Ran into this recently. Haven't quite decided how this ideally
should be handled given the context of OpenVAS in its current
state.
Variables in a function in NASL do not _need_ to be declared.
A variable appears to be local in scope if a local_var definition
for it existed within the function. It appears to be global
in scope otherwise. If the variable is not declared at all,
it will be created, automatically, with a global scope.
What this means is that if a function forgets to declare
a variable as local, it will default to global. The function
and its users will happily continue to work UNTIL a caller's
variable coincides with the function's default globally scoped
variable, in which case the function clobber's the caller's
variable.
While the quick fix is to simply ensure that functions
always declare variables with a local_var declaration, it
doesn't solve the problem of a function forgetting to
do this, and accidentally using a var that might override
a NASL. Its incredibly easy to do, and virtually undetectable
until you start debugging a bit of code that has your own
variable clobbered.
Some examples:
default_account.inc (line 83: soc; line 99: res)
http_keepalive.inc (line 221: soc)
misc_func.inc (lines 428+ vars len, i, ret, _bits, char_count)
slad_ssh.inc (various vars, including "port", "sock")
ssh_func.inc (ss_ssh_func.inc), function base64decode, variables
a[], i[], o[]
function mac_compute(), var "hash"
At this point doing a visual review, I gave up (there's more out
there, I'm pretty sure).
Some thoughts we've had:
1) Change the nasl "compiler" to force all variables to be
explictly declared;
2) Default undeclared variables to a local scope;
3) Have a "lint" style checker that examined functions and
warned of global variable usage, which could then be vetted
as acceptable (or not)
Any thoughts?
Thomas
_______________________________________________
Openvas-discuss mailing list
[email protected]
http://lists.wald.intevation.org/mailman/listinfo/openvas-discuss