From 5cee2e9bc76bd07695d671935a260afed1e9ae99 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 28 Sep 2015 00:39:43 +0200 Subject: [PATCH] Fix shell line rendering use of after free. --- sh/showline.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sh/showline.cpp b/sh/showline.cpp index d0f2f4cf..b37afe99 100644 --- a/sh/showline.cpp +++ b/sh/showline.cpp @@ -259,9 +259,12 @@ bool show_line_optimized(struct show_line* show_state, const char* line, size_t show_line_change_cursor(show_state, cursor_wcp); - free(show_state->current_line); - show_state->current_line = strdup(line); - assert(show_state->current_line); + if ( show_state->current_line != line ) + { + free(show_state->current_line); + show_state->current_line = strdup(line); + assert(show_state->current_line); + } show_state->current_cursor = cursor; return true; @@ -342,9 +345,12 @@ void show_line(struct show_line* show_state, const char* line, size_t cursor) show_state->wcp_current = wcp; - free(show_state->current_line); - show_state->current_line = strdup(line); - assert(show_state->current_line); + if ( show_state->current_line != line ) + { + free(show_state->current_line); + show_state->current_line = strdup(line); + assert(show_state->current_line); + } show_state->current_cursor = cursor; show_state->invalidated = false;