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-bash/2016-12/msg00043.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 *** ../bash-4.4-patched/lib/readline/history.c 2016-11-11 13:42:49.000000000 -0500
21 --- lib/readline/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 *** ../bash-4.4/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
94 --- patchlevel.h 2016-10-01 11:01:28.000000000 -0400
97 looks for to find the patch level (for the sccs version string). */
99 ! #define PATCHLEVEL 8
101 #endif /* _PATCHLEVEL_H_ */
103 looks for to find the patch level (for the sccs version string). */
105 ! #define PATCHLEVEL 9
107 #endif /* _PATCHLEVEL_H_ */