Skip to content

Commit

Permalink
save: Restore the screen if failed to start sudo
Browse files Browse the repository at this point in the history
Similarly to the crash fixed by #2967, which happens if sudo failed,
a crash also happens when sudo even fails to start. The reason for
the crash is also similar: nil dereference of screen.Screen caused by
the fact that we do not restore temporarily disabled screen.

To reproduce this crash, set the `sucmd` option to some non-existing
command, e.g. `aaa`, and try to save a file with root privileges.
  • Loading branch information
dmaluka committed Oct 15, 2023
1 parent 1231d24 commit 87fb92e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions internal/buffer/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func overwriteFile(name string, enc encoding.Encoding, fn func(io.Writer) error,
// contents to its stdin it might hang because the kernel's pipe size
// is too small to handle the full file contents all at once
if e := cmd.Start(); e != nil && err == nil {
screen.TempStart(screenb)
return err
}
} else if writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
Expand Down

0 comments on commit 87fb92e

Please sign in to comment.