aboutsummaryrefslogtreecommitdiff
path: root/internal/crud/cli_edit.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-15 07:51:06 +0530
committerishaan <contact@ishaan.cc>2026-07-15 07:51:06 +0530
commitd369e5611df643bd83f951a94b468ef272c1bf3e (patch)
treee9b12ca81bafc53cfad7933578f2665e183bf4f2 /internal/crud/cli_edit.go
parent8ebc072fb0ceae229196e8d3d8ff15bbbc049fdd (diff)
bunch of fixes
defer file.Close() after os.OpenFile clear(sensitive) before each os.Exit(1) Shared utils.StdinScanner with 512KB buffer bytes.Equal for password comparison, append instead of string() + []byte()
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 {