From b856fc4664e985f986fa38a76e38364d44a63be2 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 30 Jan 2020 17:29:30 +0100 Subject: [PATCH] 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. --- src/files.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 63a403ce..c0efa32e 100644 --- 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];