Skip to content

Commit 670e9ec

Browse files
committed
Do not allow to execute empty lists. Fix serious bug leading to an infinite loop when iterating through a stack trace.
1 parent fef7699 commit 670e9ec

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Sources/LispKit/Compiler/Compiler.swift

+2
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ public final class Compiler {
683683
inTailPos tail: Bool) throws -> Bool {
684684
let cp = self.checkpointer.checkpoint()
685685
switch expr {
686+
case .null:
687+
throw RuntimeError.eval(.executeEmptyList)
686688
case .symbol(let sym):
687689
try self.pushValueOf(sym, in: env)
688690
case .pair(.symbol(let sym), let cdr):

Sources/LispKit/Compiler/EvalError.swift

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public enum EvalError: Int, Hashable {
5454
case notBoundInEnvironment
5555
case bindingImmutable
5656
case nonApplicativeValue
57+
case executeEmptyList
5758
case illegalRadix
5859
case argumentError
5960
case noMatchingCase
@@ -221,6 +222,8 @@ public enum EvalError: Int, Hashable {
221222
return "unable to assign value to immutable binding for symbol $0"
222223
case .nonApplicativeValue:
223224
return "cannot apply arguments to $0"
225+
case .executeEmptyList:
226+
return "cannot execute empty application"
224227
case .illegalRadix:
225228
return "illegal radix: $0"
226229
case .argumentError:

Sources/LispKit/Runtime/VirtualMachine.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ public final class VirtualMachine: ManagedObject {
559559
}
560560
stackTrace.append(proc)
561561
if fp > 2 {
562-
guard case .fixnum(let newfp) = self.stack[fp &- 3] else {
562+
guard case .fixnum(let newfp) = self.stack[fp &- 3], Int(newfp) < fp else {
563563
// This may happen if an error is thrown
564564
return stackTrace
565565
}

0 commit comments

Comments
 (0)