mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Add more validation to --volume flag for run and create
Return error if the host and container paths is a relative path. Only absolute paths allowed. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #695 Approved by: rhatdan
This commit is contained in:
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/sysinfo"
|
"github.com/docker/docker/pkg/sysinfo"
|
||||||
@ -97,6 +98,9 @@ func parseVolumes(volumes []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateVolumeHostDir(hostDir string) error {
|
func validateVolumeHostDir(hostDir string) error {
|
||||||
|
if !filepath.IsAbs(hostDir) {
|
||||||
|
return errors.Errorf("invalid host path, must be an absolute path %q", hostDir)
|
||||||
|
}
|
||||||
if _, err := os.Stat(hostDir); err != nil {
|
if _, err := os.Stat(hostDir); err != nil {
|
||||||
return errors.Wrapf(err, "error checking path %q", hostDir)
|
return errors.Wrapf(err, "error checking path %q", hostDir)
|
||||||
}
|
}
|
||||||
@ -104,8 +108,8 @@ func validateVolumeHostDir(hostDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateVolumeCtrDir(ctrDir string) error {
|
func validateVolumeCtrDir(ctrDir string) error {
|
||||||
if ctrDir[0] != '/' {
|
if !filepath.IsAbs(ctrDir) {
|
||||||
return errors.Errorf("invalid container directory path %q", ctrDir)
|
return errors.Errorf("invalid container path, must be an absolute path %q", ctrDir)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user