Skip to content

Commit

Permalink
Merge pull request #1380 from dqminh/fix-empty-cap-panic
Browse files Browse the repository at this point in the history
fix panic regression when config doesnt have caps
  • Loading branch information
hqhq authored Mar 21, 2017
2 parents 767783a + 09c72ce commit 3f3dbc5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ func finalizeNamespace(config *initConfig) error {
return err
}

capabilities := config.Config.Capabilities
capabilities := &configs.Capabilities{}
if config.Capabilities != nil {
capabilities = config.Capabilities
} else if config.Config.Capabilities != nil {
capabilities = config.Config.Capabilities
}
w, err := newContainerCapList(capabilities)
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,57 @@ func TestProcessEnv(t *testing.T) {
}
}

func TestProcessEmptyCaps(t *testing.T) {
if testing.Short() {
return
}
root, err := newTestRoot()
ok(t, err)
defer os.RemoveAll(root)

rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)

config := newTemplateConfig(rootfs)
config.Capabilities = nil

container, err := factory.Create("test", config)
ok(t, err)
defer container.Destroy()

var stdout bytes.Buffer
pconfig := libcontainer.Process{
Cwd: "/",
Args: []string{"sh", "-c", "cat /proc/self/status"},
Env: standardEnvironment,
Stdin: nil,
Stdout: &stdout,
}
err = container.Run(&pconfig)
ok(t, err)

// Wait for process
waitProcess(&pconfig, t)

outputStatus := string(stdout.Bytes())

lines := strings.Split(outputStatus, "\n")

effectiveCapsLine := ""
for _, l := range lines {
line := strings.TrimSpace(l)
if strings.Contains(line, "CapEff:") {
effectiveCapsLine = line
break
}
}

if effectiveCapsLine == "" {
t.Fatal("Couldn't find effective caps: ", outputStatus)
}
}

func TestProcessCaps(t *testing.T) {
if testing.Short() {
return
Expand Down

0 comments on commit 3f3dbc5

Please sign in to comment.