commit b856fc4664e985f986fa38a76e38364d44a63be2
parent faa96ead4451e531ad60840d8eb5ab5bb852fd15
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 30 Jan 2020 17:29:30 +0100
locking: check two magic bytes, to verify that it is a lock file
Also, when the check fails, then nano should continue and simply
open the file, just like Vim.
This fixes https://savannah.gnu.org/bugs/?57698.
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/files.c b/src/files.c
@@ -333,13 +333,20 @@ int do_lockfile(const char *filename, bool ask_the_user)
close(lockfd);
- if (readtot < 48) {
+ if (readtot < 1024) {
statusline(MILD, _("Error reading lock file %s: "
"Not enough data read"), lockfilename);
free(lockbuf);
goto free_the_name;
}
+ if (lockbuf[0] != 0x62 || lockbuf[1] != 0x30) {
+ statusline(ALERT, _("Bad lock file is ignored: %s"), lockfilename);
+ free(lockbuf);
+ retval = 0;
+ goto free_the_name;
+ }
+
strncpy(lockprog, &lockbuf[2], 10);
lockpid = (((unsigned char)lockbuf[27] * 256 + (unsigned char)lockbuf[26]) * 256 +
(unsigned char)lockbuf[25]) * 256 + (unsigned char)lockbuf[24];