compiler API: final cleanups; improve security by diabling 'gorge' and friends

This commit is contained in:
Andreas Rumpf
2018-05-29 09:07:24 +02:00
parent a5701d6b71
commit 688c54d8f1
9 changed files with 55 additions and 28 deletions

View File

@@ -5,3 +5,5 @@ echo "top level statements are executed!"
proc hostProgramRunsThis*(a, b: float): float =
result = addFloats(a, b, 1.0)
let hostProgramWantsThis* = "my secret"

View File

@@ -1,6 +1,7 @@
discard """
output: '''top level statements are executed!
2.0
my secret
'''
"""
@@ -16,7 +17,7 @@ proc main() =
quit "cannot find Nim's standard library"
var intr = createInterpreter("myscript.nim", [std, getAppDir()])
intr.declareRoutine("*", "exposed", "addFloats", proc (a: VmArgs) =
intr.implementRoutine("*", "exposed", "addFloats", proc (a: VmArgs) =
setResult(a, getFloat(a, 0) + getFloat(a, 1) + getFloat(a, 2))
)
@@ -31,6 +32,16 @@ proc main() =
echo res.floatVal
else:
echo "bug!"
let foreignValue = selectUniqueSymbol(intr, "hostProgramWantsThis")
if foreignValue == nil:
quit "script does not export a global of the name: hostProgramWantsThis"
let val = intr.getGlobalValue(foreignValue)
if val.kind in {nkStrLit..nkTripleStrLit}:
echo val.strVal
else:
echo "bug!"
destroyInterpreter(intr)
main()