mirror of https://github.com/docker/docs.git
Merge pull request #3567 from tianon/dockerfile-add-symlink
Stop ADD from following symlinks outside the context when passed as the first argument
This commit is contained in:
commit
feb3f98418
14
buildfile.go
14
buildfile.go
|
@ -287,13 +287,24 @@ func (b *buildFile) CmdVolume(args string) error {
|
||||||
|
|
||||||
func (b *buildFile) checkPathForAddition(orig string) error {
|
func (b *buildFile) checkPathForAddition(orig string) error {
|
||||||
origPath := path.Join(b.contextPath, orig)
|
origPath := path.Join(b.contextPath, orig)
|
||||||
|
if p, err := filepath.EvalSymlinks(origPath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("%s: no such file or directory", orig)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
origPath = p
|
||||||
|
}
|
||||||
if !strings.HasPrefix(origPath, b.contextPath) {
|
if !strings.HasPrefix(origPath, b.contextPath) {
|
||||||
return fmt.Errorf("Forbidden path outside the build context: %s (%s)", orig, origPath)
|
return fmt.Errorf("Forbidden path outside the build context: %s (%s)", orig, origPath)
|
||||||
}
|
}
|
||||||
_, err := os.Stat(origPath)
|
_, err := os.Stat(origPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("%s: no such file or directory", orig)
|
return fmt.Errorf("%s: no such file or directory", orig)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,8 +319,11 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
|
||||||
}
|
}
|
||||||
fi, err := os.Stat(origPath)
|
fi, err := os.Stat(origPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("%s: no such file or directory", orig)
|
return fmt.Errorf("%s: no such file or directory", orig)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
if err := archive.CopyWithTar(origPath, destPath); err != nil {
|
if err := archive.CopyWithTar(origPath, destPath); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue