mirror of
https://github.com/containers/podman.git
synced 2025-05-22 17:46:52 +08:00
Ignore result of EvalSymlinks on ENOENT
When the path does not exist, filepath.EvalSymlinks returns an empty string - so we can't just ignore ENOENT, we have to discard the result if an ENOENT is returned. Should fix Jira issue RHEL-37948 Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -3,9 +3,7 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -237,20 +235,18 @@ func readOnlyValidateConfig(bucket *bolt.Bucket, toCheck dbConfigValidation) (bo
|
|||||||
// which is symlinked to /var/home.
|
// which is symlinked to /var/home.
|
||||||
if toCheck.isPath {
|
if toCheck.isPath {
|
||||||
if dbValue != "" {
|
if dbValue != "" {
|
||||||
// Ignore ENOENT on both, on a fresh system some paths
|
checkedVal, err := evalSymlinksIfExists(dbValue)
|
||||||
// may not exist this early in Libpod init.
|
if err != nil {
|
||||||
dbVal, err := filepath.EvalSymlinks(dbValue)
|
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
|
||||||
return false, fmt.Errorf("evaluating symlinks on DB %s path %q: %w", toCheck.name, dbValue, err)
|
return false, fmt.Errorf("evaluating symlinks on DB %s path %q: %w", toCheck.name, dbValue, err)
|
||||||
}
|
}
|
||||||
dbValue = dbVal
|
dbValue = checkedVal
|
||||||
}
|
}
|
||||||
if ourValue != "" {
|
if ourValue != "" {
|
||||||
ourVal, err := filepath.EvalSymlinks(ourValue)
|
checkedVal, err := evalSymlinksIfExists(ourValue)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil {
|
||||||
return false, fmt.Errorf("evaluating symlinks on configured %s path %q: %w", toCheck.name, ourValue, err)
|
return false, fmt.Errorf("evaluating symlinks on configured %s path %q: %w", toCheck.name, ourValue, err)
|
||||||
}
|
}
|
||||||
ourValue = ourVal
|
ourValue = checkedVal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
@ -379,21 +378,24 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
|
|||||||
|
|
||||||
checkField := func(fieldName, dbVal, ourVal string, isPath bool) error {
|
checkField := func(fieldName, dbVal, ourVal string, isPath bool) error {
|
||||||
if isPath {
|
if isPath {
|
||||||
// Evaluate symlinks. Ignore ENOENT. No guarantee all
|
// Tolerate symlinks when possible - most relevant for OStree systems
|
||||||
// directories exist this early in Libpod init.
|
// and rootless containers, where we want to put containers in /home,
|
||||||
|
// which is symlinked to /var/home.
|
||||||
|
// Ignore ENOENT as reasonable, as some paths may not exist in early Libpod
|
||||||
|
// init.
|
||||||
if dbVal != "" {
|
if dbVal != "" {
|
||||||
dbValClean, err := filepath.EvalSymlinks(dbVal)
|
checkedVal, err := evalSymlinksIfExists(dbVal)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot evaluate symlinks on DB %s path %q: %w", fieldName, dbVal, err)
|
return fmt.Errorf("cannot evaluate symlinks on DB %s path %q: %w", fieldName, dbVal, err)
|
||||||
}
|
}
|
||||||
dbVal = dbValClean
|
dbVal = checkedVal
|
||||||
}
|
}
|
||||||
if ourVal != "" {
|
if ourVal != "" {
|
||||||
ourValClean, err := filepath.EvalSymlinks(ourVal)
|
checkedVal, err := evalSymlinksIfExists(ourVal)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot evaluate symlinks on our %s path %q: %w", fieldName, ourVal, err)
|
return fmt.Errorf("cannot evaluate symlinks on our %s path %q: %w", fieldName, ourVal, err)
|
||||||
}
|
}
|
||||||
ourVal = ourValClean
|
ourVal = checkedVal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -288,3 +289,22 @@ func writeStringToPath(path, contents, mountLabel string, uid, gid int) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the given path exists, evaluate any symlinks in it. If it does not, clean
|
||||||
|
// the path and return it. Used to try and verify path equality in a somewhat
|
||||||
|
// sane fashion.
|
||||||
|
func evalSymlinksIfExists(toCheck string) (string, error) {
|
||||||
|
checkedVal, err := filepath.EvalSymlinks(toCheck)
|
||||||
|
if err != nil {
|
||||||
|
// If the error is not ENOENT, something more serious has gone
|
||||||
|
// wrong, return it.
|
||||||
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
// This is an ENOENT. On ENOENT, EvalSymlinks returns "".
|
||||||
|
// We don't want that. Return a cleaned version of the original
|
||||||
|
// path.
|
||||||
|
return filepath.Clean(toCheck), nil
|
||||||
|
}
|
||||||
|
return checkedVal, nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user