From 55565fa0377f97cf09bfab365707e08b0156c11b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 2 Jul 2019 10:57:48 +0200 Subject: prog: fix minimization bugs Fix several nasty bugs in minimization that could lead to almost arbitrary results. These bugs affected both crash minimization and corpus population. Extend the randomized test to catch these bugs. Add additional asserts to code to catch similar bugs in future. Reported-by @xairy --- prog/minimization_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'prog/minimization_test.go') diff --git a/prog/minimization_test.go b/prog/minimization_test.go index cfac164d8..a6145db9d 100644 --- a/prog/minimization_test.go +++ b/prog/minimization_test.go @@ -142,15 +142,23 @@ func TestMinimize(t *testing.T) { func TestMinimizeRandom(t *testing.T) { target, rs, iters := initTest(t) iters /= 10 // Long test. + r := rand.New(rs) for i := 0; i < iters; i++ { for _, crash := range []bool{false, true} { p := target.Generate(rs, 5, nil) - Minimize(p, len(p.Calls)-1, crash, func(p1 *Prog, callIndex int) bool { - return false - }) - Minimize(p, len(p.Calls)-1, crash, func(p1 *Prog, callIndex int) bool { + copyP := p.Clone() + minP, _ := Minimize(p, len(p.Calls)-1, crash, func(p1 *Prog, callIndex int) bool { + if r.Intn(2) == 0 { + return false + } + copyP = p1.Clone() return true }) + got := string(minP.Serialize()) + want := string(copyP.Serialize()) + if got != want { + t.Fatalf("program:\n%s\ngot:\n%v\nwant:\n%s", string(p.Serialize()), got, want) + } } } } -- cgit mrf-deployment