Skip to content

Commit 25473ec

Browse files
Merge pull request #5032 from nalind/abspaths
Make sure that pathnames picked up from the environment are absolute
2 parents 1a001de + cc619c2 commit 25473ec

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

internal/util/util.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/containers/storage/pkg/chrootarchive"
1616
"github.com/containers/storage/pkg/unshare"
1717
v1 "github.com/opencontainers/image-spec/specs-go/v1"
18+
"github.com/sirupsen/logrus"
1819
)
1920

2021
// LookupImage returns *Image to corresponding imagename or id
@@ -53,7 +54,11 @@ func NormalizePlatform(platform v1.Platform) v1.Platform {
5354
// GetTempDir returns base for a temporary directory on host.
5455
func GetTempDir() string {
5556
if tmpdir, ok := os.LookupEnv("TMPDIR"); ok {
56-
return tmpdir
57+
abs, err := filepath.Abs(tmpdir)
58+
if err == nil {
59+
return abs
60+
}
61+
logrus.Warnf("ignoring TMPDIR from environment, evaluating it: %v", err)
5762
}
5863
containerConfig, err := config.Default()
5964
if err != nil {

pkg/parse/parse.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
internalParse "github.com/containers/buildah/internal/parse"
2020
internalUtil "github.com/containers/buildah/internal/util"
2121
"github.com/containers/buildah/pkg/sshagent"
22+
"github.com/containers/common/pkg/auth"
2223
"github.com/containers/common/pkg/config"
2324
"github.com/containers/common/pkg/parse"
2425
"github.com/containers/image/v5/docker/reference"
@@ -449,9 +450,13 @@ func SystemContextFromFlagSet(flags *pflag.FlagSet, findFlagFunc func(name strin
449450

450451
func getAuthFile(authfile string) string {
451452
if authfile != "" {
452-
return authfile
453+
absAuthfile, err := filepath.Abs(authfile)
454+
if err == nil {
455+
return absAuthfile
456+
}
457+
logrus.Warnf("ignoring passed-in auth file path, evaluating it: %v", err)
453458
}
454-
return os.Getenv("REGISTRY_AUTH_FILE")
459+
return auth.GetDefaultAuthFile()
455460
}
456461

457462
// PlatformFromOptions parses the operating system (os) and architecture (arch)

pkg/sshagent/sshagent.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,13 @@ func NewSource(paths []string) (*Source, error) {
201201
if len(paths) == 0 {
202202
socket = os.Getenv("SSH_AUTH_SOCK")
203203
if socket == "" {
204-
return nil, errors.New("$SSH_AUTH_SOCK not set")
204+
return nil, errors.New("SSH_AUTH_SOCK not set in environment")
205205
}
206+
absSocket, err := filepath.Abs(socket)
207+
if err != nil {
208+
return nil, fmt.Errorf("evaluating SSH_AUTH_SOCK in environment: %w", err)
209+
}
210+
socket = absSocket
206211
}
207212
for _, p := range paths {
208213
if socket != "" {

0 commit comments

Comments
 (0)