aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-04-26 14:26:41 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-04-28 16:52:22 +0200
commitdcd4b58785fe71ff05ae045693f89b23b670ab28 (patch)
tree2461db908c5b12d0b2355c85f379ba07e9953108
parente3ecea2e7fc6b80cc715c596105f4cf890e7e2e6 (diff)
prog: make program parsing more permissive
Don't error on wrong vma with value in non strict mode. Add more tests and fix use of cmp package (prog.Syscall is not comparable anymore).
-rw-r--r--prog/encoding.go3
-rw-r--r--prog/encoding_test.go26
2 files changed, 24 insertions, 5 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 9a06c6d4b..f99ff9d84 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -347,7 +347,8 @@ func (p *parser) parseArg(typ Type) (Arg, error) {
func (p *parser) parseArgImpl(typ Type) (Arg, error) {
if typ == nil && p.Char() != 'n' {
- return nil, fmt.Errorf("non-nil argument for nil type")
+ p.eatExcessive(true, "non-nil argument for nil type")
+ return nil, nil
}
switch p.Char() {
case '0':
diff --git a/prog/encoding_test.go b/prog/encoding_test.go
index b5d17d007..2464f35da 100644
--- a/prog/encoding_test.go
+++ b/prog/encoding_test.go
@@ -10,8 +10,6 @@ import (
"reflect"
"sort"
"testing"
-
- "github.com/google/go-cmp/cmp"
)
func setToArray(s map[string]struct{}) []string {
@@ -294,6 +292,24 @@ func TestDeserialize(t *testing.T) {
Out: `test$str2(&(0x7f0000000000)='foo\x00')`,
StrictErr: `bad string value "baz\x00", expect ["foo\x00" "bar\x00"]`,
},
+ {
+ In: `test$opt2(&(0x7f0000000000))`,
+ Out: `test$opt2(0x0)`,
+ },
+ {
+ In: `test$opt2(&(0x7f0000000001))`,
+ Out: `test$opt2(0x0)`,
+ StrictErr: `unaligned vma address 0x1`,
+ },
+ {
+ In: `test$opt2(&(0x7f0000000000)=nil)`,
+ Out: `test$opt2(0x0)`,
+ },
+ {
+ In: `test$opt2(&(0x7f0000000000)='foo')`,
+ Out: `test$opt2(0x0)`,
+ StrictErr: `non-nil argument for nil type`,
+ },
})
}
@@ -335,8 +351,8 @@ func TestSerializeDeserializeRandom(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- diff := cmp.Diff(decoded0, decoded1)
- t.Logf("decoded diff: %v", diff)
+ t.Logf("decoded0: %+v", decoded0)
+ t.Logf("decoded1: %+v", decoded1)
t.Fatalf("was: %q\ngot: %q\nprogram:\n%s",
data0[:n0], data1[:n1], p0.Serialize())
}
@@ -358,6 +374,8 @@ func testSerializeDeserialize(t *testing.T, p0 *Prog, data0, data1 []byte) (bool
t.Fatal(err)
}
if !bytes.Equal(data0[:n0], data1[:n1]) {
+ t.Logf("PROG0:\n%s\n", p0.Serialize())
+ t.Logf("PROG1:\n%s\n", p1.Serialize())
return false, n0, n1
}
return true, 0, 0