history: use an unfreed 'position_history' to avoid a possible crash

The reload_positions_if_needed() routine can free the existing
'position_history' and allocate a new one.  Using the old one,
from before the reload, could lead to a crash.

This fixes https://savannah.gnu.org/bugs/?55792.
Reported-by: Enrico Mioso <mrkiko.rs@gmail.com>

Bug existed since the reloading of the position-history file was
introduced, a year and a half ago, in commit bfc53f30.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
master
Brand Huntsman 2019-02-27 02:40:18 -07:00 committed by Benno Schulenberg
parent 70da1889ee
commit a5ef013e82
1 changed files with 2 additions and 1 deletions

View File

@ -591,7 +591,7 @@ void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
* set line and column to the retrieved values. */ * set line and column to the retrieved values. */
bool has_old_position(const char *file, ssize_t *line, ssize_t *column) bool has_old_position(const char *file, ssize_t *line, ssize_t *column)
{ {
poshiststruct *posptr = position_history; poshiststruct *posptr;
char *fullpath = get_full_path(file); char *fullpath = get_full_path(file);
if (fullpath == NULL) if (fullpath == NULL)
@ -599,6 +599,7 @@ bool has_old_position(const char *file, ssize_t *line, ssize_t *column)
reload_positions_if_needed(); reload_positions_if_needed();
posptr = position_history;
while (posptr != NULL && strcmp(posptr->filename, fullpath) != 0) while (posptr != NULL && strcmp(posptr->filename, fullpath) != 0)
posptr = posptr->next; posptr = posptr->next;