Skip to content

Commit

Permalink
Fix a bug where --pids-limit was parsed incorrectly
Browse files Browse the repository at this point in the history
The --pids-limit flag was using strconv.ParseInt with bad
arguments, resulting in it being unable to parse standard
integers (1024, for example, would produce an 'out of range'
error).

Change the arguments to make sense (base 10, max 32-bit) and
add a test to ensure we don't regress again.

Fixes containers#6908

Signed-off-by: Matthew Heon <[email protected]>
  • Loading branch information
mheon committed Jul 15, 2020
1 parent 5262c53 commit 9810e58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func createInit(c *cobra.Command) error {
}
if c.Flags().Changed("pids-limit") {
val := c.Flag("pids-limit").Value.String()
pidsLimit, err := strconv.ParseInt(val, 0, 10)
pidsLimit, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return err
}
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,4 +1015,21 @@ USER mail`
Expect(session.ExitCode()).To(Equal(0))
}
})

It("podman run verify pids-limit", func() {
cgroupsv2, err := cgroups.IsCgroup2UnifiedMode()
Expect(err).To(BeNil())

if !cgroupsv2 {
// Need v2 to ensure that cgroupfs looks the way we
// expect.
Skip("Test requires cgroups v2 to be enabled")
}

limit := "4321"
session := podmanTest.Podman([]string{"run", "--pids-limit", limit, "--rm", ALPINE, "cat", "/sys/fs/cgroup/pids.max"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring(limit))
})
})

0 comments on commit 9810e58

Please sign in to comment.