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
commit 688c54d8f1
9 changed files with 55 additions and 28 deletions

View file

@ -9,6 +9,9 @@
# implements the command dispatcher and several commands
when not defined(nimcore):
{.error: "nimcore MUST be defined for Nim's core tooling".}
import
llstream, strutils, ast, astalgo, lexer, syntaxes, renderer, options, msgs,
os, condsyms, rodread, rodwrite, times,

View file

@ -5,6 +5,7 @@ path:"llvm"
path:"$projectPath/.."
define:booting
define:nimcore
#import:"$projectpath/testability"
@if windows:
@ -13,6 +14,5 @@ define:booting
define:useStdoutAsStdmsg
cs:partial
#define:useNodeIds
#gc:markAndSweep

View file

@ -29,7 +29,7 @@ iterator exportedSymbols*(i: Interpreter): PSym =
s = nextIter(it, i.mainModule.tab)
proc selectUniqueSymbol*(i: Interpreter; name: string;
symKinds: set[TSymKind]): PSym =
symKinds: set[TSymKind] = {skLet, skVar}): PSym =
## Can be used to access a unique symbol of ``name`` and
## the given ``symKinds`` filter.
assert i != nil
@ -55,8 +55,11 @@ proc callRoutine*(i: Interpreter; routine: PSym; args: openArray[PNode]): PNode
assert i != nil
result = vm.execProc(PCtx i.graph.vm, routine, args)
proc declareRoutine*(i: Interpreter; pkg, module, name: string;
impl: proc (a: VmArgs) {.closure, gcsafe.}) =
proc getGlobalValue*(i: Interpreter; letOrVar: PSym): PNode =
result = vm.getGlobalValue(PCtx i.graph.vm, letOrVar)
proc implementRoutine*(i: Interpreter; pkg, module, name: string;
impl: proc (a: VmArgs) {.closure, gcsafe.}) =
assert i != nil
let vm = PCtx(i.graph.vm)
vm.registerCallback(pkg & "." & module & "." & name, impl)

View file

@ -972,7 +972,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
when hasFFI:
let prcValue = c.globals.sons[prc.position-1]
if prcValue.kind == nkEmpty:
globalError(c.config, c.debug[pc], "canot run " & prc.name.s)
globalError(c.config, c.debug[pc], "cannot run " & prc.name.s)
let newValue = callForeignFunction(prcValue, prc.typ, tos.slots,
rb+1, rc-1, c.debug[pc])
if newValue.kind != nkEmpty:
@ -1336,14 +1336,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
regs[ra].node.strVal = opSlurp(regs[rb].node.strVal, c.debug[pc],
c.module, c.config)
of opcGorge:
decodeBC(rkNode)
inc pc
let rd = c.code[pc].regA
when defined(nimcore):
decodeBC(rkNode)
inc pc
let rd = c.code[pc].regA
createStr regs[ra]
regs[ra].node.strVal = opGorge(regs[rb].node.strVal,
regs[rc].node.strVal, regs[rd].node.strVal,
c.debug[pc], c.config)[0]
createStr regs[ra]
regs[ra].node.strVal = opGorge(regs[rb].node.strVal,
regs[rc].node.strVal, regs[rd].node.strVal,
c.debug[pc], c.config)[0]
else:
globalError(c.config, c.debug[pc], "VM is not built with 'gorge' support")
of opcNError:
decodeB(rkNode)
let a = regs[ra].node

View file

@ -107,15 +107,16 @@ proc registerAdditionalOps*(c: PCtx) =
wrap1f_math(ceil)
wrap2f_math(fmod)
wrap2s(getEnv, ospathsop)
wrap1s(existsEnv, ospathsop)
wrap2svoid(putEnv, ospathsop)
wrap1s(dirExists, osop)
wrap1s(fileExists, osop)
wrap2svoid(writeFile, systemop)
wrap1s(readFile, systemop)
systemop getCurrentExceptionMsg
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
systemop gorgeEx
when defined(nimcore):
wrap2s(getEnv, ospathsop)
wrap1s(existsEnv, ospathsop)
wrap2svoid(putEnv, ospathsop)
wrap1s(dirExists, osop)
wrap1s(fileExists, osop)
wrap2svoid(writeFile, systemop)
wrap1s(readFile, systemop)
systemop getCurrentExceptionMsg
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
systemop gorgeEx
macrosop getProjectPath