Skip to content

Commit 27593b9

Browse files
Merge pull request #26225 from Luap99/df-panic
system df --verbose don't crash
2 parents 3b91669 + 415668c commit 27593b9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cmd/podman/system/df.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ func (d *dfContainer) ContainerID() string {
275275
}
276276

277277
func (d *dfContainer) Image() string {
278-
return d.SystemDfContainerReport.Image[0:12]
278+
if len(d.SystemDfContainerReport.Image) >= 12 {
279+
return d.SystemDfContainerReport.Image[0:12]
280+
}
281+
return ""
279282
}
280283

281284
func (d *dfContainer) Command() string {

test/system/320-system-df.bats

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ function setup_file() {
3434
is "$output" '.*"Local Volumes".*"Size":"0B"' "Total containers reported"
3535
}
3636

37+
# Regression test for https://github.com/containers/podman/issues/26224
38+
@test "podman system df - with rootfs container" {
39+
pod=p-$(safename)
40+
# create a pod which creates an infra container based on a rootfs
41+
run_podman pod create --name $pod
42+
43+
run_podman system df
44+
assert "${lines[1]}" =~ "Images *1 *0.*"
45+
assert "${lines[2]}" =~ "Containers *1 *0.*"
46+
run_podman system df --verbose
47+
assert "${lines[5]}" =~ \
48+
"[0-9a-f]{12} *0.*[0-9a-f]{12}-infra" \
49+
"system df --verbose, 'Containers', infra line"
50+
51+
run_podman pod rm -f $pod
52+
}
53+
3754
@test "podman system df --format json functionality" {
3855
# Run two dummy containers, one which exits, one which stays running
3956
cname_stopped=c-stopped-$(safename)

0 commit comments

Comments
 (0)