[v3,01/12] Zero-initialize linux note sections

Message ID 20180814200609.19999-2-pedromfc@linux.ibm.com
State New
Headers show
Series
  • GDB support for more powerpc registers on linux
Related show

Commit Message

Pedro Franco de Carvalho Aug. 14, 2018, 8:05 p.m.
This patches changes linux-tdep.c so that the buffer used to write
note sections when generating a core file is zero-initialized.  This
way, bytes that are not collected won't contain random
data (e.g. padding bytes).

gdb/ChangeLog:
YYYY-MM-DD  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-tdep.c (linux_collect_regset_section_cb): Use
	std::vector<char> instead of char * for buf.  Remove xfree.
---
 gdb/linux-tdep.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

-- 
2.13.6

Patch

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 3cfa2a5aa4..2bcd2390c5 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1583,7 +1583,9 @@  linux_collect_regset_section_cb (const char *sect_name, int size,
 				 const struct regset *regset,
 				 const char *human_name, void *cb_data)
 {
-  char *buf;
+  /* This is intentionally zero-initialized by using std::vector, so
+     that any padding bytes in the core file will show as 0.  */
+  std::vector<char> buf (size);
   struct linux_collect_regset_section_cb_data *data
     = (struct linux_collect_regset_section_cb_data *) cb_data;
 
@@ -1592,19 +1594,17 @@  linux_collect_regset_section_cb (const char *sect_name, int size,
 
   gdb_assert (regset && regset->collect_regset);
 
-  buf = (char *) xmalloc (size);
-  regset->collect_regset (regset, data->regcache, -1, buf, size);
+  regset->collect_regset (regset, data->regcache, -1, buf.data (), size);
 
   /* PRSTATUS still needs to be treated specially.  */
   if (strcmp (sect_name, ".reg") == 0)
     data->note_data = (char *) elfcore_write_prstatus
       (data->obfd, data->note_data, data->note_size, data->lwp,
-       gdb_signal_to_host (data->stop_signal), buf);
+       gdb_signal_to_host (data->stop_signal), buf.data ());
   else
     data->note_data = (char *) elfcore_write_register_note
       (data->obfd, data->note_data, data->note_size,
-       sect_name, buf, size);
-  xfree (buf);
+       sect_name, buf.data (), size);
 
   if (data->note_data == NULL)
     data->abort_iteration = 1;