GNU Binutils with patches for OS216
Revision | 32a1adcccf05f98e95a2a451066af810e121bdd9 (tree) |
---|---|
Time | 2019-09-24 06:35:05 |
Author | Andrew Burgess <andrew.burgess@embe...> |
Commiter | Andrew Burgess |
gdb/readline: fix use of an undefined variable
This commit in binutils-gdb:
Which corresponds to this commit in upstream readline:
Introduced a use of an undefined variable, which can be seen using
valgrind:
The problem can be traced back to init_line_structures. The very
first time this function is ever called its MINSIZE parameter is
always 0 and the global LINE_SIZE is 1024. Prior to the above
mentioned commits we spot that the line_state variables have not yet
been initialised, and allocate them some new buffer, then we enter
this loop:
which would initialise everything from the incoming minimum up to the
potentially extended upper line size.
The problem is that the above patches added a new condition that would
bump up the minsize like this:
So, the first time this function is called the incoming MINSIZE is 0,
the LINE_SIZE global is 1024, and if the _rl_screenwidth is 80, we see
that MINSIZE will be pushed up to 80. We still notice that the line
state is uninitialised and allocate some buffers, then we enter the
initialisation loop:
And initialise from 80 to 1023 i the newly allocated buffers, leaving
0 to 79 uninitialised.
To confirm this is an issue, if we then look at rl_redisplay we see
that a call to init_line_structures is followed first by a call to
rl_on_new_line, which does initialise visible_line[0], but not
invisible_line[0]. Later in rl_redisplay we have this logic:
The use of invisible_line[0] here will be undefined.
Considering how this variable was originally initialised before the
above patches, this patch modifies the initialisation loop in
init_line_structures, to use the original value of MINSIZE. With this
change the valgrind warning goes away.
readline/ChangeLog:
PR cli/24980
* display.c (init_line_structures): Initialise line_state using
original minsize value.
@@ -1,3 +1,9 @@ | ||
1 | +2019-09-18 Andrew Burgess <andrew.burgess@embecosm.com> | |
2 | + | |
3 | + PR cli/24980 | |
4 | + * display.c (init_line_structures): Initialise line_state using | |
5 | + original minsize value. | |
6 | + | |
1 | 7 | 2019-08-13 Christian Biesinger <cbiesinger@google.com> |
2 | 8 | |
3 | 9 | * colors.c (_rl_print_color_indicator): Remove unnecessary |
@@ -602,6 +602,7 @@ static void | ||
602 | 602 | init_line_structures (int minsize) |
603 | 603 | { |
604 | 604 | register int n; |
605 | + int original_minsize = minsize; | |
605 | 606 | |
606 | 607 | if (minsize <= _rl_screenwidth) /* XXX - for gdb */ |
607 | 608 | minsize = _rl_screenwidth + 1; |
@@ -622,7 +623,7 @@ init_line_structures (int minsize) | ||
622 | 623 | invisible_line = (char *)xrealloc (invisible_line, line_size); |
623 | 624 | } |
624 | 625 | |
625 | - for (n = minsize; n < line_size; n++) | |
626 | + for (n = original_minsize; n < line_size; n++) | |
626 | 627 | { |
627 | 628 | visible_line[n] = 0; |
628 | 629 | invisible_line[n] = 1; |