diff options
author | Brent Baude <bbaude@redhat.com> | 2020-06-01 08:59:07 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-06-01 10:07:58 -0500 |
commit | 8c1883721c28d09c5c3629db7e0d77344f5f7bd9 (patch) | |
tree | 1d8d325fc307b1054d35628dc8870b9e06407df9 /pkg/api/handlers/libpod/images.go | |
parent | 22713d62e2860052e21e5e985fba169834709fdc (diff) | |
download | podman-8c1883721c28d09c5c3629db7e0d77344f5f7bd9.tar.gz podman-8c1883721c28d09c5c3629db7e0d77344f5f7bd9.tar.bz2 podman-8c1883721c28d09c5c3629db7e0d77344f5f7bd9.zip |
Fix leak of empty tarball
In cases of trying to export an image, if the image was not found, we leaked an empty tarball or directory depending on the format.
Fixes: #6409
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers/libpod/images.go')
-rw-r--r-- | pkg/api/handlers/libpod/images.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 4b277d39c..54e202103 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -181,6 +181,12 @@ func ExportImage(w http.ResponseWriter, r *http.Request) { errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) return } + name := utils.GetName(r) + newImage, err := runtime.ImageRuntime().NewFromLocal(name) + if err != nil { + utils.ImageNotFound(w, name, err) + return + } switch query.Format { case define.OCIArchive, define.V2s2Archive: tmpfile, err := ioutil.TempFile("", "api.tar") @@ -204,13 +210,6 @@ func ExportImage(w http.ResponseWriter, r *http.Request) { utils.Error(w, "unknown format", http.StatusInternalServerError, errors.Errorf("unknown format %q", query.Format)) return } - name := utils.GetName(r) - newImage, err := runtime.ImageRuntime().NewFromLocal(name) - if err != nil { - utils.ImageNotFound(w, name, err) - return - } - if err := newImage.Save(r.Context(), name, query.Format, output, []string{}, false, query.Compress); err != nil { utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, err) return |