aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2021-01-05 10:47:41 +0100
committerDmitry Vyukov <dvyukov@google.com>2021-01-05 11:16:20 +0100
commitc2de3766243ed8955ab83e59bd5e4d60cb81bac9 (patch)
tree2bbaa1b9d8189e5c2830e757c709705e342cc1e7
parent270cde8ebe422a3197eec97faf00d3f10b0b0148 (diff)
prog: fix oob panic in rotatorState.Select
Reported-by: ManhNDd Fixes #2372
-rw-r--r--prog/rotation.go3
-rw-r--r--prog/rotation_test.go13
2 files changed, 16 insertions, 0 deletions
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} {