tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
4
Task/Runtime-evaluation/Tcl/runtime-evaluation-1.tcl
Normal file
4
Task/Runtime-evaluation/Tcl/runtime-evaluation-1.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
set four 4
|
||||
set result1 [eval "expr {$four + 5}"] ;# string input
|
||||
|
||||
set result2 [eval [list expr [list $four + 5]]] ;# list input
|
||||
21
Task/Runtime-evaluation/Tcl/runtime-evaluation-2.tcl
Normal file
21
Task/Runtime-evaluation/Tcl/runtime-evaluation-2.tcl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Create an interpreter with a default set of restrictions
|
||||
interp create -safe restrictedContext
|
||||
|
||||
# Our secret variable
|
||||
set v "secret"
|
||||
|
||||
# Allow some guarded access to the secret from the restricted context.
|
||||
interp alias restrictedContext doubleSecret {} example
|
||||
proc example {} {
|
||||
global v
|
||||
lappend v $v
|
||||
return [llength $v]
|
||||
}
|
||||
|
||||
# Evaluate a script in the restricted context
|
||||
puts [restrictedContext eval {
|
||||
append v " has been leaked"
|
||||
catch {file delete yourCriticalFile.txt} ;# Will be denied!
|
||||
return "there are [doubleSecret] words in the secret: the magic number is [expr {4 + 5}]"
|
||||
}]; # --> there are 2 words in the secret: the magic number is 9
|
||||
puts $v; # --> secret secret
|
||||
8
Task/Runtime-evaluation/Tcl/runtime-evaluation-3.tcl
Normal file
8
Task/Runtime-evaluation/Tcl/runtime-evaluation-3.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set i [interp create]
|
||||
interp limit $i commands -value [expr [$i eval info cmdcount]+20] -granularity 1
|
||||
interp eval $i {
|
||||
set x 0
|
||||
while {1} { # Infinite loop! Bwahahahaha!
|
||||
puts "Counting up... [incr x]"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue