From 2b21a445652488099a64067e13b98576f78f0363 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Mon, 24 Jul 2017 15:05:08 +0200 Subject: prog: return error instead of panic when parsing --- prog/encoding_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'prog/encoding_test.go') diff --git a/prog/encoding_test.go b/prog/encoding_test.go index f23a92cc7..f4036b458 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -6,6 +6,7 @@ package prog import ( "fmt" "reflect" + "regexp" "sort" "testing" ) @@ -93,3 +94,32 @@ func TestCallSetRandom(t *testing.T) { } } } + +func TestDeserialize(t *testing.T) { + tests := []struct { + data string + err *regexp.Regexp + }{ + { + "syz_test$struct(&(0x7f0000000000)={0x0, {0x0}})", + nil, + }, + { + "syz_test$struct(&(0x7f0000000000)=0x0)", + regexp.MustCompile(`bad const type.*`), + }, + } + for _, test := range tests { + _, err := Deserialize([]byte(test.data)) + if err != nil { + if test.err == nil { + t.Fatalf("deserialization failed with\n%s\ndata:\n%s\n", err, test.data) + } + if !test.err.MatchString(err.Error()) { + t.Fatalf("deserialization failed with\n%s\nwhich doesn't match\n%s\ndata:\n%s\n", err, test.err, test.data) + } + } else if test.err != nil { + t.Fatalf("deserialization should have failed with:\n%s\ndata:\n%s\n", test.err, test.data) + } + } +} -- cgit mrf-deployment