From 8fefee2d41b4cce49a791895327aaa8cea7c2c5d Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 10 Feb 2024 11:56:23 +0100 Subject: [PATCH] undo: prevent a use-after-free, reported by `correctmost` When the cursor is on the last line, and an undo removes this line, do not let 'openfile->current' become invalid. This fixes https://savannah.gnu.org/bugs/?65279. Bug existed since version 6.3, commit eea3e1f0. (It should have been fixed in commit 9410a556, more than a year ago.) --- src/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.c b/src/utils.c index d39e6098..071846c2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -436,6 +436,8 @@ void remove_magicline(void) { if (openfile->filebot->data[0] == '\0' && openfile->filebot != openfile->filetop) { + if (openfile->current == openfile->filebot) + openfile->current = openfile->current->prev; openfile->filebot = openfile->filebot->prev; delete_node(openfile->filebot->next); openfile->filebot->next = NULL;