Skip to content

Commit

Permalink
Fix path trimming: Left/Right => Prefix/Suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed May 12, 2021
1 parent 223aa3b commit 5dd7b5c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func ExtractDirs(img v1.Image, dirs map[string]string, opts ...Option) error {
for s, d := range dirs {
var err error
if s != "/" {
s = strings.TrimRight(s, "/")
s = strings.TrimSuffix(s, "/")
}
if d != "/" {
d, err = filepath.Abs(strings.TrimRight(d, "/"))
d, err = filepath.Abs(strings.TrimSuffix(d, "/"))
if err != nil {
return errors.Wrap(err, "invalid destination")
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func findPath(dirs map[string]string, path string) (string, error) {
}
for s := filepath.Dir(path); ; s = filepath.Dir(s) {
if d, ok := dirs[s]; ok {
j := filepath.Clean(filepath.Join(d, strings.TrimLeft(path, s)))
j := filepath.Clean(filepath.Join(d, strings.TrimPrefix(path, s)))
// Ensure that the path after cleaning does not escape the target prefix.
if !strings.HasPrefix(j, d) {
return "", ErrIllegalPath
Expand Down

0 comments on commit 5dd7b5c

Please sign in to comment.