aboutsummaryrefslogtreecommitdiffstats
path: root/prog
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
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')
-rw-r--r--prog/encoding.go2
-rw-r--r--prog/encoding_test.go30
2 files changed, 31 insertions, 1 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 93af09457..c9d5d40c5 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -216,7 +216,7 @@ func parseArg(typ sys.Type, p *parser, vars map[string]Arg) (Arg, error) {
case *sys.VmaType:
arg = pointerArg(typ, 0, 0, 0, nil)
default:
- panic(fmt.Sprintf("bad const type %+v", typ))
+ return nil, fmt.Errorf("bad const type %+v", typ)
}
case 'r':
id := p.Ident()
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)
+ }
+ }
+}