Skip to content

Commit fc7cfeb

Browse files
buffer: check sudo binary exists before creating backup
Verify the sudo command is available via exec.LookPath() before creating the backup in safeWrite(). This avoids bogus backup files when the sudo binary is not found. Signed-off-by: Nilton Perim Neto <niltonperimneto@gmail.com>
1 parent 60adb71 commit fc7cfeb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/buffer/save.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ func (b *Buffer) saveToFile(filename string, withSudo bool, autoSave bool) error
238238
return errors.New("Cannot save scratch buffer")
239239
}
240240

241+
if withSudo {
242+
_, err := exec.LookPath(config.GlobalSettings["sucmd"].(string))
243+
if err != nil {
244+
return err
245+
}
246+
}
247+
241248
if !autoSave && b.Settings["rmtrailingws"].(bool) {
242249
for i, l := range b.lines {
243250
leftover := util.CharacterCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))

0 commit comments

Comments
 (0)