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:
Tianon Gravi 2014-01-14 11:48:54 -08:00
commit feb3f98418
1 changed files with 16 additions and 2 deletions

View File

@ -287,13 +287,24 @@ func (b *buildFile) CmdVolume(args string) error {
func (b *buildFile) checkPathForAddition(orig string) error {
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) {
return fmt.Errorf("Forbidden path outside the build context: %s (%s)", orig, origPath)
}
_, err := os.Stat(origPath)
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("%s: no such file or directory", orig)
}
return err
}
return nil
}
@ -308,8 +319,11 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
}
fi, err := os.Stat(origPath)
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("%s: no such file or directory", orig)
}
return err
}
if fi.IsDir() {
if err := archive.CopyWithTar(origPath, destPath); err != nil {
return err