CVE-2024-5742: emergency_save() applied chmod/chown to a path after
the descriptor was closed, allowing a symlink swap to redirect the
ownership change to an attacker-controlled file
Backport of upstream commit 5e7a3c2e from nano v8.0, adapted to the
5.6.1 codebase (write_file signature predates the SPECIAL/NONOTES
refactor)