This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Fix 'sprintf' of potential NULL pointer in 'maint print arch'
- From: Meador Inge <meadori at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 25 Oct 2011 12:03:35 -0500
- Subject: [PATCH] Fix 'sprintf' of potential NULL pointer in 'maint print arch'
'gdbarch_dump' is in some cases passing a NULL pointer to 'sprintf'
when printing 'gdbarch->gcore_bfd_target'. Printing NULL pointers like this
is undefined behavior. With glibc passing a NULL pointer just prints "(null)".
With the MSVC libc, however, GDB crashes.
I am fixing the bug by wrapping the access to 'gdbarch->gcore_bfd_target'
with 'pstring'. The same method is already used for printing
'gdbarch->solib_symbols_extension'.
OK?
P.S. I have an FSF contributor agreement on file, but don't have write-access.
If this is OK'd and someone could commit it for me, then that would be great.
2011-10-25 Meador Inge <meadori@codesourcery.com>
gdb/
* gdbarch.sh (function_list): Use 'pstring' when printing
'gcore_bfd_target'.
* gdbarch.c: Regenerate.
---
gdb/gdbarch.c | 2 +-
gdb/gdbarch.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index ea48fa7..1ada504 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -953,7 +953,7 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdbarch_gcore_bfd_target_p (gdbarch));
fprintf_unfiltered (file,
"gdbarch_dump: gcore_bfd_target = %s\n",
- gdbarch->gcore_bfd_target);
+ pstring (gdbarch->gcore_bfd_target));
fprintf_unfiltered (file,
"gdbarch_dump: gen_return_address = <%s>\n",
host_address_to_string (gdbarch->gen_return_address));
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index bf78173..a9ca03d 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -640,7 +640,7 @@ M:LONGEST:core_xfer_shared_libraries:gdb_byte *readbuf, ULONGEST offset, LONGEST
M:char *:core_pid_to_str:ptid_t ptid:ptid
# BFD target to use when generating a core file.
-V:const char *:gcore_bfd_target:::0:0:::gdbarch->gcore_bfd_target
+V:const char *:gcore_bfd_target:::0:0:::pstring (gdbarch->gcore_bfd_target)
# If the elements of C++ vtables are in-place function descriptors rather
# than normal function pointers (which may point to code or a descriptor),
--
1.7.0.4