commit 8fefee2d41b4cce49a791895327aaa8cea7c2c5d
parent cdaa43b3967cc3bcd85400c77082d202b3e020aa
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 10 Feb 2024 11:56:23 +0100
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.)
Diffstat:
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git 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;