This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] gdb: remove local extern declaration of cli_styling
- From: Simon Marchi <simark at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 18 Sep 2019 17:34:28 -0000
- Subject: [binutils-gdb] gdb: remove local extern declaration of cli_styling
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f64eea3a594042c9cf499b17b5b166276275a051
commit f64eea3a594042c9cf499b17b5b166276275a051
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date: Wed Sep 18 13:33:33 2019 -0400
gdb: remove local extern declaration of cli_styling
Following the int -> bool conversion of boolean options (commit
491144b5e21b ("Change boolean options to bool instead of int")), I see
this ASAN error:
==357543==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55555b25d440 at pc 0x5555583ce9e1 bp 0x7fffffffd390 sp 0x7fffffffd380
READ of size 4 at 0x55555b25d440 thread T0
#0 0x5555583ce9e0 in term_cli_styling /home/simark/src/binutils-gdb/gdb/ui-file.c:111
#1 0x5555583cf8b0 in stdio_file::can_emit_style_escape() /home/simark/src/binutils-gdb/gdb/ui-file.c:308
#2 0x5555584450d2 in set_output_style /home/simark/src/binutils-gdb/gdb/utils.c:1442
#3 0x5555584491af in fprintf_styled(ui_file*, ui_file_style const&, char const*, ...) /home/simark/src/binutils-gdb/gdb/utils.c:2143
#4 0x5555582fa13c in print_gdb_version(ui_file*, bool) /home/simark/src/binutils-gdb/gdb/top.c:1339
#5 0x555557b723ab in captured_main_1 /home/simark/src/binutils-gdb/gdb/main.c:981
#6 0x555557b7353b in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1172
#7 0x555557b735d0 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1197
#8 0x55555700a53d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
#9 0x7ffff64c9ee2 in __libc_start_main (/usr/lib/libc.so.6+0x26ee2)
#10 0x55555700a30d in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x1ab630d)
0x55555b25d441 is located 0 bytes to the right of global variable 'cli_styling' defined in '/home/simark/src/binutils-gdb/gdb/cli/cli-style.c:31:6' (0x55555b25d440) of size 1
The reason of this is that we have this declaration of cli_styling in cli/cli-style.h:
extern bool cli_styling;
but ui-file.c uses its own local declaration:
extern int cli_styling;
Because of that, the code in ui-file.c thinks the variable is 4 bytes
long, when it is actually 1 byte long, so the generated code reads past
the variable.
Fix it by removing the declaration and making ui-file.c include
cli/cli-style.h.
gdb/ChangeLog:
* ui-file.c: Include cli/cli-style.h.
(term_cli_styling): Remove cli_styling declaration.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/ui-file.c | 3 +--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 421b26a..796ade3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-09-18 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * ui-file.c: Include cli/cli-style.h.
+ (term_cli_styling): Remove cli_styling declaration.
+
2019-09-18 Alan Modra <amodra@gmail.com>
* arm-tdep.c (arm_record_special_symbol): Update bfd_get_section
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index 042b13c..71b74bb 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -24,6 +24,7 @@
#include "gdb_obstack.h"
#include "gdb_select.h"
#include "gdbsupport/filestuff.h"
+#include "cli/cli-style.h"
null_file null_stream;
@@ -106,8 +107,6 @@ ui_file_isatty (struct ui_file *file)
static bool
term_cli_styling ()
{
- extern int cli_styling;
-
if (!cli_styling)
return false;