This is the mail archive of the gdb-cvs@sourceware.org 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]

[binutils-gdb] GDB: Fix some null pointer dereferences due to disassembler-options patch.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f7bb4e3a0d3738e8cce3dcded6ef12c9949cb85f

commit f7bb4e3a0d3738e8cce3dcded6ef12c9949cb85f
Author: Peter Bergner <bergner@vnet.ibm.com>
Date:   Tue Mar 7 09:49:10 2017 -0600

    GDB: Fix some null pointer dereferences due to disassembler-options patch.
    
    gdb/
    	* gdbarch.sh (pstring_ptr): New static function.
    	(gdbarch_disassembler_options): Use it.
    	(gdbarch_verify_disassembler_options): Print valid_disassembler_options,
    	not valid_disassembler_option->name.
    	* gdbarch.c: Regenerate.

Diff:
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/gdbarch.c  | 12 ++++++++++--
 gdb/gdbarch.sh | 12 ++++++++++--
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f63c09c..2427b10 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2017-03-07  Peter Bergner  <bergner@vnet.ibm.com>
 
+	* gdbarch.sh (pstring_ptr): New static function.
+	(gdbarch_disassembler_options): Use it.
+	(gdbarch_verify_disassembler_options): Print valid_disassembler_options,
+	not valid_disassembler_option->name.
+	* gdbarch.c: Regenerate.
+
+2017-03-07  Peter Bergner  <bergner@vnet.ibm.com>
+
 	* config/powerpc/ppc64-linux.mh (MH_CFLAGS): Delete.
 
 2017-03-07  Pedro Alves  <palves@redhat.com>
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index f52cf5d..87eafb2 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -84,6 +84,14 @@ pstring (const char *string)
   return string;
 }
 
+static char *
+pstring_ptr (char **string)
+{
+  if (string == NULL || *string == NULL)
+    return "(null)";
+  return *string;
+}
+
 /* Helper function to print a list of strings, represented as "const
    char *const *".  The list is printed comma-separated.  */
 
@@ -880,7 +888,7 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       core_addr_to_string_nz (gdbarch->deprecated_function_start_offset));
   fprintf_unfiltered (file,
                       "gdbarch_dump: disassembler_options = %s\n",
-                      pstring (*gdbarch->disassembler_options));
+                      pstring_ptr (gdbarch->disassembler_options));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_displaced_step_copy_insn_p() = %d\n",
                       gdbarch_displaced_step_copy_insn_p (gdbarch));
@@ -1429,7 +1437,7 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       host_address_to_string (gdbarch->unwind_sp));
   fprintf_unfiltered (file,
                       "gdbarch_dump: valid_disassembler_options = %s\n",
-                      host_address_to_string (gdbarch->valid_disassembler_options->name));
+                      host_address_to_string (gdbarch->valid_disassembler_options));
   fprintf_unfiltered (file,
                       "gdbarch_dump: value_from_register = <%s>\n",
                       host_address_to_string (gdbarch->value_from_register));
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 6902e0e..39b1f94 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1164,8 +1164,8 @@ m:const char *:gnu_triplet_regexp:void:::default_gnu_triplet_regexp::0
 m:int:addressable_memory_unit_size:void:::default_addressable_memory_unit_size::0
 
 # Functions for allowing a target to modify its disassembler options.
-v:char **:disassembler_options:::0:0::0:pstring (*gdbarch->disassembler_options)
-v:const disasm_options_t *:valid_disassembler_options:::0:0::0:host_address_to_string (gdbarch->valid_disassembler_options->name)
+v:char **:disassembler_options:::0:0::0:pstring_ptr (gdbarch->disassembler_options)
+v:const disasm_options_t *:valid_disassembler_options:::0:0::0:host_address_to_string (gdbarch->valid_disassembler_options)
 
 EOF
 }
@@ -1678,6 +1678,14 @@ pstring (const char *string)
   return string;
 }
 
+static char *
+pstring_ptr (char **string)
+{
+  if (string == NULL || *string == NULL)
+    return "(null)";
+  return *string;
+}
+
 /* Helper function to print a list of strings, represented as "const
    char *const *".  The list is printed comma-separated.  */


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