Skip to content

Commit

Permalink
Close tmpfile after writing (#685)
Browse files Browse the repository at this point in the history
* Close tmpfile after writing

Windows will not allow for deletion of a file with an open handle, 
close tmpfile after writing to prevent unencrypted tmpfiles out-living
the execution

* Update cmd/sops/edit.go

Co-authored-by: Adrian Utrilla <adrianutrilla@gmail.com>

* defer edited file close

Co-authored-by: Adrian Utrilla <adrianutrilla@gmail.com>
  • Loading branch information
lbonanomi and autrilla committed Jul 14, 2020
1 parent 4f06780 commit 09d511f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/sops/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
if err != nil {
return nil, common.NewExitError(fmt.Sprintf("Could not write output file: %s", err), codes.CouldNotWriteOutputFile)
}

// Close temporary file, since Windows won't delete the file unless it's closed beforehand
defer tmpfile.Close()

// Compute file hash to detect if the file has been edited
origHash, err := hashFile(tmpfile.Name())
Expand Down

0 comments on commit 09d511f

Please sign in to comment.