Merge pull request #20019 from holiman/minor_adminfix

eth: disallow overwrite files via admin.exportChain
This commit is contained in:
Péter Szilágyi 2019-08-30 15:35:43 +03:00 committed by GitHub
commit d5bd38384c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -168,6 +168,11 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI {
// ExportChain exports the current blockchain into a local file. // ExportChain exports the current blockchain into a local file.
func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
if _, err := os.Stat(file); err == nil {
// File already exists. Allowing overwrite could be a DoS vecotor,
// since the 'file' may point to arbitrary paths on the drive
return false, errors.New("location would overwrite an existing file")
}
// Make sure we can create the file to export into // Make sure we can create the file to export into
out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
if err != nil { if err != nil {