Branch oldpackages for 14.07
[14.07/packages.git] / utils / bash / patches / 109-upstream-bash42-009.patch
1                              BASH PATCH REPORT
2                              =================
3
4 Bash-Release:   4.2
5 Patch-ID:       bash42-009
6
7 Bug-Reported-by:        <piuma@piumalab.org>
8 Bug-Reference-ID:       <4DAAC0DB.7060606@piumalab.org>
9 Bug-Reference-URL:      http://lists.gnu.org/archive/html/bug-bash/2011-04/msg00075.html
10
11 Bug-Description:
12
13 Under certain circumstances, running `fc -l' two times in succession with a
14 relative history offset at the end of the history will result in an incorrect
15 calculation of the last history entry and a seg fault.
16
17 Patch (apply with `patch -p0'):
18
19 --- a/builtins/fc.def
20 +++ b/builtins/fc.def
21 @@ -304,7 +304,7 @@ fc_builtin (list)
22    last_hist = i - rh - hist_last_line_added;
23  
24    /* XXX */
25 -  if (saved_command_line_count > 0 && i == last_hist && hlist[last_hist] == 0)
26 +  if (i == last_hist && hlist[last_hist] == 0)
27      while (last_hist >= 0 && hlist[last_hist] == 0)
28        last_hist--;
29    if (last_hist < 0)
30 @@ -475,7 +475,7 @@ fc_gethnum (command, hlist)
31       HIST_ENTRY **hlist;
32  {
33    int sign, n, clen, rh;
34 -  register int i, j;
35 +  register int i, j, last_hist;
36    register char *s;
37  
38    sign = 1;
39 @@ -495,7 +495,15 @@ fc_gethnum (command, hlist)
40       has been enabled (interactive or not) should use it in the last_hist
41       calculation as if it were on. */
42    rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
43 -  i -= rh + hist_last_line_added;
44 +  last_hist = i - rh - hist_last_line_added;
45 +
46 +  if (i == last_hist && hlist[last_hist] == 0)
47 +    while (last_hist >= 0 && hlist[last_hist] == 0)
48 +      last_hist--;
49 +  if (last_hist < 0)
50 +    return (-1);
51 +
52 +  i = last_hist;
53  
54    /* No specification defaults to most recent command. */
55    if (command == NULL)
56 --- a/patchlevel.h
57 +++ b/patchlevel.h
58 @@ -25,6 +25,6 @@
59     regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
60     looks for to find the patch level (for the sccs version string). */
61  
62 -#define PATCHLEVEL 8
63 +#define PATCHLEVEL 9
64  
65  #endif /* _PATCHLEVEL_H_ */