Skip to content

Commit 6d2dbbc

Browse files
author
zhouhao
committed
runtimetest: fix nil deference
Signed-off-by: zhouhao <[email protected]>
1 parent 929bd5e commit 6d2dbbc

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

cmd/runtimetest/main.go

+34-16
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func validateGeneralProcess(spec *rspec.Spec) error {
105105
}
106106

107107
func validateLinuxProcess(spec *rspec.Spec) error {
108+
if spec.Process == nil {
109+
return nil
110+
}
111+
108112
validateGeneralProcess(spec)
109113

110114
uid := os.Getuid()
@@ -162,6 +166,10 @@ func validateLinuxProcess(spec *rspec.Spec) error {
162166
}
163167

164168
func validateCapabilities(spec *rspec.Spec) error {
169+
if spec.Process == nil || spec.Process.Capabilities == nil {
170+
return nil
171+
}
172+
165173
last := capability.CAP_LAST_CAP
166174
// workaround for RHEL6 which has no /proc/sys/kernel/cap_last_cap
167175
if last == capability.Cap(63) {
@@ -178,22 +186,20 @@ func validateCapabilities(spec *rspec.Spec) error {
178186
expectedCaps3 := make(map[string]bool)
179187
expectedCaps4 := make(map[string]bool)
180188
expectedCaps5 := make(map[string]bool)
181-
if spec.Process.Capabilities != nil {
182-
for _, ec := range spec.Process.Capabilities.Bounding {
183-
expectedCaps1[ec] = true
184-
}
185-
for _, ec := range spec.Process.Capabilities.Effective {
186-
expectedCaps2[ec] = true
187-
}
188-
for _, ec := range spec.Process.Capabilities.Inheritable {
189-
expectedCaps3[ec] = true
190-
}
191-
for _, ec := range spec.Process.Capabilities.Permitted {
192-
expectedCaps4[ec] = true
193-
}
194-
for _, ec := range spec.Process.Capabilities.Ambient {
195-
expectedCaps5[ec] = true
196-
}
189+
for _, ec := range spec.Process.Capabilities.Bounding {
190+
expectedCaps1[ec] = true
191+
}
192+
for _, ec := range spec.Process.Capabilities.Effective {
193+
expectedCaps2[ec] = true
194+
}
195+
for _, ec := range spec.Process.Capabilities.Inheritable {
196+
expectedCaps3[ec] = true
197+
}
198+
for _, ec := range spec.Process.Capabilities.Permitted {
199+
expectedCaps4[ec] = true
200+
}
201+
for _, ec := range spec.Process.Capabilities.Ambient {
202+
expectedCaps5[ec] = true
197203
}
198204

199205
for _, cap := range capability.List() {
@@ -259,6 +265,10 @@ func validateHostname(spec *rspec.Spec) error {
259265
}
260266

261267
func validateRlimits(spec *rspec.Spec) error {
268+
if spec.Process == nil {
269+
return nil
270+
}
271+
262272
for _, r := range spec.Process.Rlimits {
263273
rl, err := strToRlimit(r.Type)
264274
if err != nil {
@@ -311,6 +321,10 @@ func testWriteAccess(path string) error {
311321
}
312322

313323
func validateRootFS(spec *rspec.Spec) error {
324+
if spec.Root == nil {
325+
return nil
326+
}
327+
314328
if spec.Root.Readonly {
315329
err := testWriteAccess("/")
316330
if err == nil {
@@ -422,6 +436,10 @@ func validateDefaultSymlinks(spec *rspec.Spec) error {
422436
}
423437

424438
func validateDefaultDevices(spec *rspec.Spec) error {
439+
if spec.Process == nil {
440+
return nil
441+
}
442+
425443
if spec.Process.Terminal {
426444
defaultDevices = append(defaultDevices, "/dev/console")
427445
}

0 commit comments

Comments
 (0)