This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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


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  <>

	* (function_list): Use 'pstring' when printing
	* gdbarch.c: Regenerate.

 gdb/gdbarch.c  |    2 +-
 gdb/ |    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/ b/gdb/
index bf78173..a9ca03d 100755
--- a/gdb/
+++ b/gdb/
@@ -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),

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]