aboutsummaryrefslogtreecommitdiff
path: root/internal/crud/cli_edit.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/crud/cli_edit.go')
-rw-r--r--internal/crud/cli_edit.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/crud/cli_edit.go b/internal/crud/cli_edit.go
index b7b76f0..03c84df 100644
--- a/internal/crud/cli_edit.go
+++ b/internal/crud/cli_edit.go
@@ -50,7 +50,9 @@ func EditNotePass(notePath, editorString string) error {
crypt.TryMlock(newContent)
defer clear(newContent)
- os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600)
+ if err := os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600); err != nil {
+ fmt.Fprintf(os.Stderr, "warning: failed to wipe temp file %s: %v\n", tmpFile.Name(), err)
+ }
encrypted, err := crypt.EncryptBytesPass(newContent, password)
if err != nil { return err }
@@ -66,11 +68,15 @@ func EditNotePass(notePath, editorString string) error {
func deferredCleanTmpFile(tmpFile *os.File, oldContentLen int) {
tmpFileInfo, err := tmpFile.Stat()
if err != nil {
- os.WriteFile(tmpFile.Name(), make([]byte, oldContentLen), 0600)
+ if err := os.WriteFile(tmpFile.Name(), make([]byte, oldContentLen), 0600); err != nil {
+ fmt.Fprintf(os.Stderr, "warning: failed to wipe temp file %s: %v\n", tmpFile.Name(), err)
+ }
return
}
- os.WriteFile(tmpFile.Name(), make([]byte, int(tmpFileInfo.Size())), 0600)
+ if err := os.WriteFile(tmpFile.Name(), make([]byte, int(tmpFileInfo.Size())), 0600); err != nil {
+ fmt.Fprintf(os.Stderr, "warning: failed to wipe temp file %s: %v\n", tmpFile.Name(), err)
+ }
}
func EditNoteSSH(notePath, privKeyPath, editorString string) error {
@@ -151,7 +157,9 @@ func EditNoteSSH(notePath, privKeyPath, editorString string) error {
crypt.TryMlock(newContent)
defer clear(newContent)
- os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600)
+ if err := os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600); err != nil {
+ fmt.Fprintf(os.Stderr, "warning: failed to wipe temp file %s: %v\n", tmpFile.Name(), err)
+ }
encrypted, _, err := crypt.EncryptBytesSSH(newContent, pubKeys)
if err != nil {