From 6821ab8f905da68a96296b42f3769c786e32c0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Tu=C5=BCnik?= Date: Tue, 17 Nov 2020 13:54:52 +0100 Subject: [PATCH] Fix an out-of-bound array access in simulator.TestClear() --- .../simulator/cluster_snapshot_benchmark_test.go | 4 ++++ cluster-autoscaler/simulator/cluster_snapshot_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cluster-autoscaler/simulator/cluster_snapshot_benchmark_test.go b/cluster-autoscaler/simulator/cluster_snapshot_benchmark_test.go index 58b57361a9..ae51c06925 100644 --- a/cluster-autoscaler/simulator/cluster_snapshot_benchmark_test.go +++ b/cluster-autoscaler/simulator/cluster_snapshot_benchmark_test.go @@ -53,6 +53,10 @@ func createTestPods(n int) []*apiv1.Pod { } func assignPodsToNodes(pods []*apiv1.Pod, nodes []*apiv1.Node) { + if len(nodes) == 0 { + return + } + j := 0 for i := 0; i < len(pods); i++ { if j >= len(nodes) { diff --git a/cluster-autoscaler/simulator/cluster_snapshot_test.go b/cluster-autoscaler/simulator/cluster_snapshot_test.go index 448051b150..c21dc23010 100644 --- a/cluster-autoscaler/simulator/cluster_snapshot_test.go +++ b/cluster-autoscaler/simulator/cluster_snapshot_test.go @@ -240,8 +240,8 @@ func TestClear(t *testing.T) { // Run with -count=1 to avoid caching. localRand := rand.New(rand.NewSource(time.Now().Unix())) - nodeCount := localRand.Intn(100) - podCount := localRand.Intn(1000) + nodeCount := localRand.Intn(99) + 1 + podCount := localRand.Intn(999) + 1 extraNodeCount := localRand.Intn(100) extraPodCount := localRand.Intn(1000)