diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-03-07 13:12:35 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-03-13 13:16:53 +0100 |
| commit | 9b1f3e665308ee2ddd5b3f35a078219b5c509cdb (patch) | |
| tree | 56e177dcb9b249381d27abacec5e59e9d2cf410f /prog/encoding_test.go | |
| parent | 05359321bb37f035e55ccfad2cc36b0ea3b50998 (diff) | |
prog: control program length
We have _some_ limits on program length, but they are really soft.
When we ask to generate a program with 10 calls, sometimes we get
100-150 calls. There are also no checks when we accept external
programs from corpus/hub. Issue #1630 contains an example where
this crashes VM (executor limit on number of 1000 resources is
violated). Larger programs also harm the process overall (slower,
consume more memory, lead to monster reproducers, etc).
Add a set of measure for hard control over program length.
Ensure that generated/mutated programs are not too long;
drop too long programs coming from corpus/hub in manager;
drop too long programs in hub.
As a bonus ensure that mutation don't produce programs with
0 calls (which is currently possible and happens).
Fixes #1630
Diffstat (limited to 'prog/encoding_test.go')
| -rw-r--r-- | prog/encoding_test.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/prog/encoding_test.go b/prog/encoding_test.go index e5aa82146..c62e6647f 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -53,29 +53,34 @@ func TestSerializeData(t *testing.T) { func TestCallSet(t *testing.T) { t.Parallel() tests := []struct { - prog string - ok bool - calls []string + prog string + ok bool + calls []string + ncalls int }{ { "", false, []string{}, + 0, }, { "r0 = (foo)", false, []string{}, + 0, }, { "getpid()", true, []string{"getpid"}, + 1, }, { "r11 = getpid()", true, []string{"getpid"}, + 1, }, { "getpid()\n" + @@ -86,11 +91,12 @@ func TestCallSet(t *testing.T) { "close$foo(&(0x0000) = {})\n", true, []string{"getpid", "open", "close$foo"}, + 4, }, } for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { - calls, err := CallSet([]byte(test.prog)) + calls, ncalls, err := CallSet([]byte(test.prog)) if err != nil && test.ok { t.Fatalf("parsing failed: %v", err) } @@ -102,6 +108,9 @@ func TestCallSet(t *testing.T) { if !reflect.DeepEqual(callArray, test.calls) { t.Fatalf("got call set %+v, expect %+v", callArray, test.calls) } + if ncalls != test.ncalls { + t.Fatalf("got %v calls, expect %v", ncalls, test.ncalls) + } }) } } @@ -109,12 +118,13 @@ func TestCallSet(t *testing.T) { func TestCallSetRandom(t *testing.T) { target, rs, iters := initTest(t) for i := 0; i < iters; i++ { - p := target.Generate(rs, 10, nil) + const ncalls = 10 + p := target.Generate(rs, ncalls, nil) calls0 := make(map[string]struct{}) for _, c := range p.Calls { calls0[c.Meta.Name] = struct{}{} } - calls1, err := CallSet(p.Serialize()) + calls1, ncalls1, err := CallSet(p.Serialize()) if err != nil { t.Fatalf("CallSet failed: %v", err) } @@ -123,6 +133,9 @@ func TestCallSetRandom(t *testing.T) { if !reflect.DeepEqual(callArray0, callArray1) { t.Fatalf("got call set:\n%+v\nexpect:\n%+v", callArray1, callArray0) } + if ncalls1 != ncalls { + t.Fatalf("got %v calls, expect %v", ncalls1, ncalls) + } } } |
