From c2de3766243ed8955ab83e59bd5e4d60cb81bac9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 5 Jan 2021 10:47:41 +0100 Subject: prog: fix oob panic in rotatorState.Select Reported-by: ManhNDd Fixes #2372 --- prog/rotation.go | 3 +++ prog/rotation_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/prog/rotation.go b/prog/rotation.go index 0171e6ace..544f22730 100644 --- a/prog/rotation.go +++ b/prog/rotation.go @@ -150,6 +150,9 @@ func (rs *rotatorState) Select() map[*Syscall]bool { // However, a resource can be handled as dependency first, but then // handled as top resource again. In such case we will still add calls // that use this resource. + if len(rs.resources) == 0 { + return rs.Rotator.calls + } for { if len(rs.depQueue) == 0 && len(rs.calls) >= rs.goal || len(rs.calls) >= 2*rs.goal { rs.calls, _ = rs.target.transitivelyEnabled(rs.calls) diff --git a/prog/rotation_test.go b/prog/rotation_test.go index 4a7aa31cc..e218a5eb6 100644 --- a/prog/rotation_test.go +++ b/prog/rotation_test.go @@ -9,8 +9,21 @@ import ( "math/rand" "sort" "testing" + + "github.com/google/go-cmp/cmp" ) +func TestRotationResourceless(t *testing.T) { + target, rs, _ := initRandomTargetTest(t, "test", "64") + calls := map[*Syscall]bool{ + target.SyscallMap["test$int"]: true, + } + got := MakeRotator(target, calls, rand.New(rs)).Select() + if diff := cmp.Diff(calls, got); diff != "" { + t.Fatal(diff) + } +} + func TestRotationRandom(t *testing.T) { target, rs, _ := initTest(t) for _, ncalls := range []int{10, 100, 1000, 1e9} { -- cgit mrf-deployment