Skip to content

Commit

Permalink
Fix the issue that a dummy entry may cheat patch command (#1091)
Browse files Browse the repository at this point in the history
Fix #846

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
lucklove and ti-chi-bot authored Jan 25, 2021
1 parent c5c9f13 commit 7b86020
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/cluster/manager/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path"

"github.com/joomcode/errorx"
"github.com/pingcap/errors"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
Expand Down Expand Up @@ -118,8 +119,18 @@ func checkPackage(bindVersion spec.BindVersion, specManager *spec.SpecManager, n
return err
}

if exists := utils.IsExist(path.Join(cacheDir, entry)); !exists {
return fmt.Errorf("entry %s not found in package %s", entry, packagePath)
fi, err := os.Stat(path.Join(cacheDir, entry))
if err != nil {
if os.IsNotExist(err) {
return errors.Errorf("entry %s not found in package %s", entry, packagePath)
}
return errors.AddStack(err)
}
if !fi.Mode().IsRegular() {
return errors.Errorf("entry %s in package %s is not a regular file", entry, packagePath)
}
if fi.Mode()&0500 != 0500 {
return errors.Errorf("entry %s in package %s is not executable", entry, packagePath)
}

return nil
Expand Down
10 changes: 10 additions & 0 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ function cmd_subtest() {
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --overwrite
# overwrite with the same tarball twice
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --overwrite
# test patch with a non-executable entry
rm -rf tidb-server
touch tidb-server # this is a non-executable regular file
tar -czf tidb-non-executable.tar.gz tidb-server
! tiup-cluster $client --yes patch $name ./tidb-non-executable.tar.gz -R tidb
# test patch with a dir entry
rm -rf tidb-server
mkdir tidb-server
tar -czf tidb-dir-entry.tar.gz tidb-server
! tiup-cluster $client --yes patch $name ./tidb-dir-entry.tar.gz -R tidb

tiup-cluster $client --yes stop $name

Expand Down

0 comments on commit 7b86020

Please sign in to comment.