From 930bec4d3a7cfe83784ded58e5f8f88d062dd3e2 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 9 Mar 2021 11:53:50 +0100 Subject: [PATCH] podman load: fix error handling Make sure to properly return loading errors and to set the exit code accordingly. Fixes: #9672 Signed-off-by: Valentin Rothberg --- libpod/runtime_img.go | 3 ++- test/system/120-load.bats | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index abefca7884..90b11f8caf 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -316,7 +316,8 @@ func (r *Runtime) LoadImageFromSingleImageArchive(ctx context.Context, writer io } { src, err := referenceFn() if err == nil && src != nil { - if newImages, err := r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer); err == nil { + newImages, err := r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer) + if err == nil { return getImageNames(newImages), nil } saveErr = err diff --git a/test/system/120-load.bats b/test/system/120-load.bats index 902cd9f5ec..936449bdb2 100644 --- a/test/system/120-load.bats +++ b/test/system/120-load.bats @@ -26,6 +26,13 @@ verify_iid_and_name() { is "$new_img_name" "$1" "Name & tag of restored image" } +@test "podman load invalid file" { + # Regression test for #9672 to make sure invalid input yields errors. + invalid=$PODMAN_TMPDIR/invalid + echo "I am an invalid file and should cause a podman-load error" > $invalid + run_podman 125 load -i $invalid +} + @test "podman save to pipe and load" { # Generate a random name and tag (must be lower-case) local random_name=x0$(random_string 12 | tr A-Z a-z)