mirror of
https://github.com/docker/cli.git
synced 2026-09-26 09:20:58 -04:00
full diff: https://github.com/moby/go-archive/compare/v0.2.1...v0.3.0 v0.3.0 This release fixes CVE-2026-17106 / GHSA-hfg8-hc9c-6c3h, where a crafted tar archive could use links to cause extraction operations to create or overwrite files outside the intended destination directory. The issue affected Unpack, UnpackLayer, Untar, UntarUncompressed, and the ApplyLayer helpers. Users should upgrade and avoid extracting untrusted archives with earlier versions. What's Changed * archive: harden tar extraction against path traversal * archive: do not follow reparse points in chtimes * archive: fix creation time updates on Windows * archive: minor cleanups and godoc touch-up * archive: RebaseArchiveEntries: fix archive path rebasing Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
//go:build !windows
|
|
|
|
package archive
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// chtimes changes the access and modification time of a file at the given
|
|
// path relative to root.
|
|
//
|
|
// Callers must use boundTime to ensure timestamps are within the range
|
|
// supported by os.Chtimes.
|
|
func chtimes(root *os.Root, name string, atime, mtime time.Time) error {
|
|
return root.Chtimes(name, atime, mtime)
|
|
}
|
|
|
|
func lchtimes(root *os.Root, name string, atime, mtime time.Time) error {
|
|
dir, base := path.Split(filepath.ToSlash(name))
|
|
if base == "" {
|
|
return &os.PathError{Op: "lchtimes", Path: name, Err: syscall.EINVAL}
|
|
}
|
|
|
|
dir = strings.TrimSuffix(dir, "/")
|
|
if dir == "" {
|
|
dir = "."
|
|
}
|
|
|
|
parent, err := root.Open(dir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer parent.Close()
|
|
|
|
utimes := [2]unix.Timespec{
|
|
timeToTimespec(atime),
|
|
timeToTimespec(mtime),
|
|
}
|
|
// #nosec G115 -- ignore integer overflow conversion for parent.Fd
|
|
if err := unix.UtimesNanoAt(int(parent.Fd()), base, utimes[:], unix.AT_SYMLINK_NOFOLLOW); err != nil {
|
|
if errors.Is(err, unix.ENOSYS) {
|
|
return nil
|
|
}
|
|
return &os.PathError{Op: "lchtimes", Path: name, Err: err}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func timeToTimespec(time time.Time) unix.Timespec {
|
|
if time.IsZero() {
|
|
// Return UTIME_OMIT special value
|
|
return unix.Timespec{
|
|
Sec: 0,
|
|
Nsec: (1 << 30) - 2,
|
|
}
|
|
}
|
|
return unix.NsecToTimespec(time.UnixNano())
|
|
}
|