9cbe11
From 840e7dad513b86f454573ad415701c0199f78d30 Mon Sep 17 00:00:00 2001
9cbe11
From: TomSweeneyRedHat <tsweeney@redhat.com>
9cbe11
Date: Tue, 24 Mar 2020 20:10:22 -0400
9cbe11
Subject: [PATCH] Fix potential CVE in tarfile w/ symlink
9cbe11
9cbe11
Stealing @nalind 's workaround to avoid refetching
9cbe11
content after a file read failure.  Under the right
9cbe11
circumstances that could be a symlink to a file meant
9cbe11
to overwrite a good file with bad data.
9cbe11
9cbe11
Testing:
9cbe11
```
9cbe11
goodstuff
9cbe11
9cbe11
[1] 14901
9cbe11
9cbe11
127.0.0.1 - - [24/Mar/2020 20:15:50] "GET / HTTP/1.1" 200 -
9cbe11
127.0.0.1 - - [24/Mar/2020 20:15:50] "GET / HTTP/1.1" 200 -
9cbe11
no FROM statement found
9cbe11
9cbe11
goodstuff
9cbe11
```
9cbe11
9cbe11
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
9cbe11
---
9cbe11
 imagebuildah/util.go | 5 +++--
9cbe11
 1 file changed, 3 insertions(+), 2 deletions(-)
9cbe11
9cbe11
diff --git a/imagebuildah/util.go b/imagebuildah/util.go
9cbe11
index 29ea60970..5f14c9883 100644
9cbe11
--- a/vendor/github.com/containers/buildah/imagebuildah/util.go
9cbe11
+++ b/vendor/github.com/containers/buildah/imagebuildah/util.go
9cbe11
@@ -14,6 +14,7 @@ import (
9cbe11
 
9cbe11
 	"github.com/containers/buildah"
9cbe11
 	"github.com/containers/storage/pkg/chrootarchive"
9cbe11
+	"github.com/containers/storage/pkg/ioutils"
9cbe11
 	"github.com/opencontainers/runtime-spec/specs-go"
9cbe11
 	"github.com/pkg/errors"
9cbe11
 	"github.com/sirupsen/logrus"
9cbe11
@@ -57,7 +58,7 @@ func downloadToDirectory(url, dir string) error {
9cbe11
 		}
9cbe11
 		dockerfile := filepath.Join(dir, "Dockerfile")
9cbe11
 		// Assume this is a Dockerfile
9cbe11
-		if err := ioutil.WriteFile(dockerfile, body, 0600); err != nil {
9cbe11
+		if err := ioutils.AtomicWriteFile(dockerfile, body, 0600); err != nil {
9cbe11
 			return errors.Wrapf(err, "Failed to write %q to %q", url, dockerfile)
9cbe11
 		}
9cbe11
 	}
9cbe11
@@ -75,7 +76,7 @@ func stdinToDirectory(dir string) error {
9cbe11
 	if err := chrootarchive.Untar(reader, dir, nil); err != nil {
9cbe11
 		dockerfile := filepath.Join(dir, "Dockerfile")
9cbe11
 		// Assume this is a Dockerfile
9cbe11
-		if err := ioutil.WriteFile(dockerfile, b, 0600); err != nil {
9cbe11
+		if err := ioutils.AtomicWriteFile(dockerfile, b, 0600); err != nil {
9cbe11
 			return errors.Wrapf(err, "Failed to write bytes to %q", dockerfile)
9cbe11
 		}
9cbe11
 	}