Skip to content

Commit 049a5f7

Browse files
committed
libct/cap: allow New(nil)
In runtime-spec, capabilities property is optional, but libcontainer/capabilities panics when New(nil) is called. Because of this, there's a kludge in finalizeNamespace to ensure capabilities.New is not called with nil argument, and there's a TestProcessEmptyCaps to ensure runc won't panic. Let's fix this at the source, allowing libct/cap to work with nil capabilities. (The caller is fixed by the next commit.) Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent f26ec92 commit 049a5f7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libcontainer/capabilities/capabilities.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func KnownCapabilities() []string {
4747
// printing a warning instead.
4848
func New(capConfig *configs.Capabilities) (*Caps, error) {
4949
var c Caps
50+
if capConfig == nil {
51+
return &c, nil
52+
}
5053

5154
_, err := capMap()
5255
if err != nil {
@@ -103,13 +106,19 @@ type Caps struct {
103106

104107
// ApplyBoundingSet sets the capability bounding set to those specified in the whitelist.
105108
func (c *Caps) ApplyBoundingSet() error {
109+
if c.pid == nil {
110+
return nil
111+
}
106112
c.pid.Clear(capability.BOUNDING)
107113
c.pid.Set(capability.BOUNDING, c.caps[capability.BOUNDING]...)
108114
return c.pid.Apply(capability.BOUNDING)
109115
}
110116

111117
// Apply sets all the capabilities for the current process in the config.
112118
func (c *Caps) ApplyCaps() error {
119+
if c.pid == nil {
120+
return nil
121+
}
113122
c.pid.Clear(capability.CAPS | capability.BOUNDS)
114123
for _, g := range []capability.CapType{
115124
capability.EFFECTIVE,

0 commit comments

Comments
 (0)