Skip to content

Commit

Permalink
Merge pull request #6447 from baude/v2apitarleak
Browse files Browse the repository at this point in the history
Fix leak of empty tarball
  • Loading branch information
openshift-merge-robot authored Jun 1, 2020
2 parents 2c6016f + 8c18837 commit f559cec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions pkg/api/handlers/libpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var _ = Describe("Podman images", func() {
It("podman images filter before image", func() {
SkipIfRemote()
dockerfile := `FROM docker.io/library/alpine:latest
RUN apk update && apk add man
RUN apk update && apk add strace
`
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.Podman([]string{"images", "-q", "-f", "before=foobar.com/before:latest"})
Expand Down

0 comments on commit f559cec

Please sign in to comment.