binutils-gdb/gdb/cli
Andrew Burgess 0e2a21335b gdb: Avoid signed integer overflow when printing source lines
When printing source lines with calls to print_source_lines we need to
pass a start line number and an end line number.  The end line number
is calculated by calling get_lines_to_list and adding this value to
the start line number.  For example this code from list_command:

    print_source_lines (cursal.symtab, first,
                        first + get_lines_to_list (), 0);

The problem is that get_lines_to_list returns a value based on the
GDB setting `set listsize LISTSIZE`.  By default LISTSIZE is 10,
however, its also possible to set LISTSIZE to unlimited, in which
case get_lines_to_list will return INT_MAX.

As the parameter signature for print_source_lines is:

  void print_source_lines (struct symtab *, int, int,
                           print_source_lines_flags);

and `first` in the above code is an `int`, then when LISTSIZE is
`unlimited` the above code will result in signed integer overflow,
which is undefined.

The solution in this patch is a new class source_lines_range that can
be constructed from a single line number and a direction (forward or
backward).  The range is then constructed from the line number and the
value of get_lines_to_list.

gdb/ChangeLog:

	* cli/cli-cmds.c (list_command): Pass a source_lines_range to
	print_source_lines.
	* source.c (print_source_lines_base): Update line number check.
	(print_source_lines): New function.
	(source_lines_range::source_lines_range): New function.
	* source.h (class source_lines_range): New class.
	(print_source_lines): New declaration.
2019-01-09 14:11:24 +00:00
..
cli-cmds.c gdb: Avoid signed integer overflow when printing source lines 2019-01-09 14:11:24 +00:00
cli-cmds.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-decode.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-decode.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-dump.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-interp.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-interp.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-logging.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-script.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-script.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-setshow.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-setshow.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-style.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-style.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-utils.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-utils.h Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00