Skip to content

Commit cd3faf9

Browse files
author
Dongsu Park
committed
validation: fix nil dereference when handling multierror in hooks_stdin
As `stdinStateCheck()` can return nil for errs, we need to access to `errs.Error()` only when errs is not nil. So conditionally compose newError for both cases, errs == nil and errs != nil, to avoid panics like that: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4f5a02] goroutine 1 [running]: github.com/opencontainers/runtime-tools/vendor/github.com/hashicorp/go-multierror.(*Error).Error(0x0, 0x7dfc20, 0xc420224480) .../github.com/opencontainers/runtime-tools/vendor/github.com/hashicorp/go-multierror/multierror.go:15 +0x22 main.main() .../github.com/opencontainers/runtime-tools/validation/hooks_stdin.go:154 +0x11ba ``` Signed-off-by: Dongsu Park <[email protected]>
1 parent 9b65419 commit cd3faf9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

validation/hooks_stdin.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ func main() {
151151
}
152152
for _, file := range []string{"prestart", "poststart", "poststop"} {
153153
errs := stdinStateCheck(outputDir, file, expectedState)
154-
util.SpecErrorOK(t, errs.ErrorOrNil() == nil, specerror.NewError(specerror.PosixHooksStateToStdin, fmt.Errorf("the state of the container MUST be passed to %q hook over stdin", file), rspecs.Version), errors.New(errs.Error()))
154+
var newError error
155+
if errs == nil {
156+
newError = errors.New("")
157+
} else {
158+
newError = errors.New(errs.Error())
159+
}
160+
util.SpecErrorOK(t, errs.ErrorOrNil() == nil, specerror.NewError(specerror.PosixHooksStateToStdin, fmt.Errorf("the state of the container MUST be passed to %q hook over stdin", file), rspecs.Version), newError)
155161
}
156162

157163
t.AutoPlan()

0 commit comments

Comments
 (0)