1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Close tmpfile after writing (#685)

* 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>
This commit is contained in:
lbonanomi
2020-07-14 15:25:59 -04:00
committed by GitHub
parent 4f06780ab2
commit 09d511f69f

View File

@@ -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())