Skip to content

Commit

Permalink
Merge pull request #104 from skx/101-fuzzer
Browse files Browse the repository at this point in the history
Resolved fuzzer failures.
  • Loading branch information
skx authored Nov 21, 2022
2 parents ae9c925 + 94d85b0 commit a199f66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ func (ev *Eval) eval(exp primitive.Primitive, e *env.Environment, expandMacro bo
//
// Now we're only dealing with lists
//
listExp := exp.(primitive.List)
listExp, listOk := exp.(primitive.List)

//
// But just in case we're not ..
//
if !listOk {
return primitive.Error(fmt.Sprintf("argument not a list for a function call: %v", exp))
}

//
// Is this an empty list? Then just return it
Expand Down
4 changes: 4 additions & 0 deletions eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ a
{input: "(define blah (lambda (a:number) (print a))) (blah '(3))", output: "ERROR{TypeError - argument a to blah was supposed to be number, got list}"},
{input: "(define blah (lambda (a:function) (print a))) (blah '(3))", output: "ERROR{TypeError - argument a to blah was supposed to be function, got list}"},
{input: "(define blah (lambda (a:any) (print a))) (blah '(3))", output: "(3)"},

// fuzz errors
{input: "(defmacro! unless(fn*()`(~!)))(unless )", output: "ERROR{argument '(lambda (x) (if x #f #t))' not a function}"},
{input: "(ord 0)", output: "ERROR{argument not a character/string, got number}"},
}

for _, test := range tests {
Expand Down
1 change: 1 addition & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func FuzzYAL(f *testing.F) {
"invalid character literal",
"is not a symbol",
"must have even length",
"not a character",
"not a function",
"not a hash",
"not a list",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("(defmacro! unless(fn*()`(~!)))(unless )")

0 comments on commit a199f66

Please sign in to comment.