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.)
This commit is contained in:
Benno Schulenberg
2024-02-10 11:56:23 +01:00
parent cdaa43b396
commit 8fefee2d41

View File

@@ -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;