Skip to content

Commit 292cf7c

Browse files
committed
eth: disallow overwrite files via admin.exportChain
1 parent cc9eb91 commit 292cf7c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

eth/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI {
168168

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

0 commit comments

Comments
 (0)