aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding_test.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@gmail.com>2017-07-24 16:43:50 +0200
committerGitHub <noreply@github.com>2017-07-24 16:43:50 +0200
commit6bbb0ce7e4e15656bb20f434583cc56e2acb492e (patch)
tree9624bcd0cecae843b31216fa5de7978d6d675572 /prog/encoding_test.go
parent1e06f3e00fe12ed48282e1c896f57b0c2874eb44 (diff)
parent2b21a445652488099a64067e13b98576f78f0363 (diff)
Merge pull request #297 from xairy/up-fix-enconding
prog: return error instead of panic when parsing
Diffstat (limited to 'prog/encoding_test.go')
-rw-r--r--prog/encoding_test.go30
1 files changed, 30 insertions, 0 deletions
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)
+ }
+ }
+}