sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.15k stars 208 forks source link

visudo creates file even if editor is closed without saving #294

Closed ReillyBrogan closed 12 months ago

ReillyBrogan commented 1 year ago

I noticed this when in the process of updating the Solus sudo package to 1.9.14p2.

If you run visudo /non-existant-file and then exit without saving the file (for instance, in Nano using ctrl+x) the end result will be that visudo will create an empty /non-existant-file.

This seems undesirable to me, perhaps the user simply misspelled a file name and exited to use a different file name. In that case they would not expect the misspelled file to be created.

millert commented 12 months ago

Things can get a little complicated. For example, if you add a #include line to sudoers, visudo must create the file, even if it is empty. Otherwise the file will not parse properly. The change I committed will prevent a new top-level sudoers file from being created via visudo if the editor is exited without writing any changes.