CLI: Fix installing plugins on windows (#19061)

Fixes #19022
This commit is contained in:
Marcus Efraimsson
2019-09-13 18:12:52 +02:00
committed by GitHub
parent 7b7b95341e
commit 2acffbeb10
2 changed files with 19 additions and 13 deletions

View File

@ -199,14 +199,14 @@ func extractFiles(body []byte, pluginName string, filePath string, allowSymlinks
}
for _, zf := range r.File {
newFileName := RemoveGitBuildFromName(pluginName, zf.Name)
if !isPathSafe(newFileName, path.Join(filePath, pluginName)) {
if !isPathSafe(newFileName, filepath.Join(filePath, pluginName)) {
return xerrors.Errorf("filepath: %v tries to write outside of plugin directory: %v. This can be a security risk.", zf.Name, path.Join(filePath, pluginName))
}
newFile := path.Join(filePath, newFileName)
if zf.FileInfo().IsDir() {
err := os.Mkdir(newFile, 0755)
if permissionsError(err) {
if os.IsPermission(err) {
return fmt.Errorf(permissionsDeniedMessage, newFile)
}
} else {
@ -234,10 +234,6 @@ func extractFiles(body []byte, pluginName string, filePath string, allowSymlinks
return nil
}
func permissionsError(err error) bool {
return err != nil && strings.Contains(err.Error(), "permission denied")
}
func isSymlink(file *zip.File) bool {
return file.Mode()&os.ModeSymlink == os.ModeSymlink
}
@ -269,7 +265,7 @@ func extractFile(file *zip.File, filePath string) (err error) {
dst, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
if err != nil {
if permissionsError(err) {
if os.IsPermission(err) {
return xerrors.Errorf(permissionsDeniedMessage, filePath)
}
return errutil.Wrap("Failed to open file", err)