5 Patch-ID: readline70-002
7 Bug-Reported-by: Hong Cho <hong.cho@citrix.com>
8 Bug-Reference-ID: <c30b5fe62b2543af8297e47ca487c29c@SJCPEX02CL02.citrite.net>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-readline/2016-12/msg00002.html
13 There is a race condition in add_history() that can be triggered by a fatal
14 signal arriving between the time the history length is updated and the time
15 the history list update is completed. A later attempt to reference an
16 invalid history entry can cause a crash.
18 Patch (apply with `patch -p0'):
20 *** ../readline-7.0-patched/history.c 2016-11-11 13:42:49.000000000 -0500
21 --- history.c 2016-12-05 10:37:51.000000000 -0500
29 if (history_stifled && (history_length == history_max_entries))
32 /* Copy the rest of the entries, moving down one slot. Copy includes
35 - for (i = 0; i < history_length; i++)
36 - the_history[i] = the_history[i + 1];
38 memmove (the_history, the_history + 1, history_length * sizeof (HIST_ENTRY *));
44 /* Copy the rest of the entries, moving down one slot. Copy includes
46 memmove (the_history, the_history + 1, history_length * sizeof (HIST_ENTRY *));
48 + new_length = history_length;
53 history_size = DEFAULT_HISTORY_INITIAL_SIZE;
54 the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *));
59 history_size = DEFAULT_HISTORY_INITIAL_SIZE;
60 the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *));
66 xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
72 xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
74 ! new_length = history_length + 1;
79 temp = alloc_history_entry ((char *)string, hist_inittime ());
81 ! the_history[history_length] = (HIST_ENTRY *)NULL;
82 ! the_history[history_length - 1] = temp;
86 temp = alloc_history_entry ((char *)string, hist_inittime ());
88 ! the_history[new_length] = (HIST_ENTRY *)NULL;
89 ! the_history[new_length - 1] = temp;
90 ! history_length = new_length;
93 *** ../readline-7.0/patchlevel 2013-11-15 08:11:11.000000000 -0500
94 --- patchlevel 2014-03-21 08:28:40.000000000 -0400
97 # Do not edit -- exists only for use by patch
101 # Do not edit -- exists only for use by patch