-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
- Loading branch information
Showing
3 changed files
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ func extractTarDirectory(dirPath, dirName string, r io.Reader, buf []byte) error | |
|
||
// Name check | ||
filename := header.Name | ||
Check failure Code scanning / CodeQL Arbitrary file write extracting an archive containing symbolic links High
Unresolved path from an archive header, which may point outside the archive root, is used in
symlink creation Error loading related location Loading Unresolved path from an archive header, which may point outside the archive root, is used in symlink creation. |
||
filePathRel, err := ensureBasePath(dirPath, dirName, filename) | ||
filePathRel, err := resolveRelToBase(dirPath, dirName, filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -214,10 +214,10 @@ func extractTarDirectory(dirPath, dirName string, r io.Reader, buf []byte) error | |
} | ||
} | ||
|
||
// ensureBasePath ensures the target path is in the base path, | ||
// resolveRelToBase ensures the target path is in the base path, | ||
// returning its relative path to the base path. | ||
// target can be either an absolute path or a relative path. | ||
func ensureBasePath(baseAbs, baseRel, target string) (string, error) { | ||
func resolveRelToBase(baseAbs, baseRel, target string) (string, error) { | ||
base := baseRel | ||
if filepath.IsAbs(target) { | ||
// ensure base and target are consistent | ||
|
@@ -257,7 +257,7 @@ func ensureLinkPath(baseAbs, baseRel, link, target string) (string, error) { | |
path = filepath.Join(filepath.Dir(link), target) | ||
} | ||
// ensure path is under baseAbs or baseRel | ||
if _, err := ensureBasePath(baseAbs, baseRel, path); err != nil { | ||
if _, err := resolveRelToBase(baseAbs, baseRel, path); err != nil { | ||
return "", err | ||
} | ||
return target, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters