Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit a086d97

Browse files
committed
sanitize filepaths in tar prepper
1 parent 4b4b0cb commit a086d97

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) {
129129

130130
if pkgutil.IsTar(image) {
131131
return &pkgutil.TarPrepper{
132-
Source: image,
132+
Source: filepath.Clean(image),
133133
Client: cli,
134134
}, nil
135135
}

pkg/util/tar_utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ package util
1919
import (
2020
"archive/tar"
2121
"fmt"
22-
"github.com/pkg/errors"
23-
"github.com/sirupsen/logrus"
2422
"io"
2523
"os"
2624
"path/filepath"
2725
"strings"
26+
27+
"github.com/pkg/errors"
28+
"github.com/sirupsen/logrus"
2829
)
2930

3031
// Map of target:linkname
@@ -48,7 +49,7 @@ func unpackTar(tr *tar.Reader, path string, whitelist []string) error {
4849
return err
4950
}
5051
if strings.Contains(header.Name, ".wh.") {
51-
rmPath := filepath.Join(path, header.Name)
52+
rmPath := filepath.Clean(filepath.Join(path, header.Name))
5253
// Remove the .wh file if it was extracted.
5354
if _, err := os.Stat(rmPath); !os.IsNotExist(err) {
5455
if err := os.Remove(rmPath); err != nil {
@@ -63,7 +64,7 @@ func unpackTar(tr *tar.Reader, path string, whitelist []string) error {
6364
}
6465
continue
6566
}
66-
target := filepath.Join(path, header.Name)
67+
target := filepath.Clean(filepath.Join(path, header.Name))
6768
// Make sure the target isn't part of the whitelist
6869
if checkWhitelist(target, whitelist) {
6970
continue
@@ -143,7 +144,7 @@ func unpackTar(tr *tar.Reader, path string, whitelist []string) error {
143144
logrus.Errorf("Failed to create symlink between %s and %s: %s", header.Linkname, target, err)
144145
}
145146
case tar.TypeLink:
146-
linkname := filepath.Join(path, header.Linkname)
147+
linkname := filepath.Clean(filepath.Join(path, header.Linkname))
147148
// Check if the linkname already exists
148149
if _, err := os.Stat(linkname); !os.IsNotExist(err) {
149150
// If it exists, create the hard link

0 commit comments

Comments
 (0)