Skip to content

Commit 509cd99

Browse files
bryan-coxopenshift-cherrypick-robot
authored andcommitted
fix(test): prevent nil pointer dereference in ginkgo test runner
Add nil checks to recordTestResultInMonitor, recordTestResultInLog, and TestEnded functions to prevent segmentation faults when testRunResult is nil during error conditions like network connectivity issues.
1 parent 3bbd10e commit 509cd99

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/test/ginkgo/status.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ginkgo
33
import (
44
"fmt"
55
"io"
6+
"os"
67
"sort"
78
"sync"
89
)
@@ -38,6 +39,11 @@ func (s *testSuiteProgress) TestEnded(testName string, testRunResult *testRunRes
3839
s.lock.Lock()
3940
defer s.lock.Unlock()
4041

42+
if testRunResult == nil {
43+
fmt.Fprintln(os.Stderr, "testRunResult is nil")
44+
return
45+
}
46+
4147
if isTestFailed(testRunResult.testState) {
4248
s.failures++
4349
}

pkg/test/ginkgo/test_runner.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func recordTestResultInLogWithoutOverlap(testRunResult *testRunResultHandle, tes
221221
}
222222

223223
func recordTestResultInLog(testRunResult *testRunResultHandle, out io.Writer, includeSuccessfulOutput bool) {
224+
if testRunResult == nil {
225+
fmt.Fprintln(os.Stderr, "testRunResult is nil")
226+
return
227+
}
228+
224229
// output the status of the test
225230
switch testRunResult.testState {
226231
case TestFlaked:
@@ -257,6 +262,11 @@ func recordTestResultInLog(testRunResult *testRunResultHandle, out io.Writer, in
257262
}
258263

259264
func recordTestResultInMonitor(testRunResult *testRunResultHandle, monitorRecorder monitorapi.Recorder) {
265+
if testRunResult == nil {
266+
fmt.Fprintln(os.Stderr, "testRunResult is nil")
267+
return
268+
}
269+
260270
eventLevel := monitorapi.Warning
261271

262272
msg := monitorapi.NewMessage().HumanMessage("e2e test finished")

0 commit comments

Comments
 (0)