Don't pass NULL to memcpy in gdb
authorTom Tromey <tromey@adacore.com>
Tue, 31 Mar 2020 13:29:53 +0000 (07:29 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 31 Mar 2020 13:29:53 +0000 (07:29 -0600)
I compiled gdb with -fsanitize=undefined and ran the test suite.

A couple of reports came from passing NULL to memcpy, e.g.:

[...]btrace-common.cc:176:13: runtime error: null pointer passed as argument 2, which is declared to never be null

While it would be better to fix this in the standard, in the meantime
it seems easy to avoid this error.

gdb/ChangeLog
2020-03-31  Tom Tromey  <tromey@adacore.com>

* dwarf2/abbrev.c (abbrev_table::read): Conditionally call
memcpy.

gdbsupport/ChangeLog
2020-03-31  Tom Tromey  <tromey@adacore.com>

* btrace-common.cc (btrace_data_append): Conditionally call
memcpy.

gdb/ChangeLog
gdb/dwarf2/abbrev.c
gdbsupport/ChangeLog
gdbsupport/btrace-common.cc

index 67aa87214213df112b9c29e0e8839b205b117cbd..d3873da04b4f0e094d632e434b6133c754b499ae 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-31  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2/abbrev.c (abbrev_table::read): Conditionally call
+       memcpy.
+
 2020-03-30  Nelson Chu  <nelson.chu@sifive.com>
 
        * features/riscv/32bit-csr.xml: Regenerated.
index 59ff138b33d4d71fa8146e1fcc228eb99cb2418c..b85018060fa30b16b338b72ac99e75e6a9b7a495 100644 (file)
@@ -168,8 +168,9 @@ abbrev_table::read (struct objfile *objfile,
       cur_abbrev->attrs =
        XOBNEWVEC (&abbrev_table->m_abbrev_obstack, struct attr_abbrev,
                   cur_abbrev->num_attrs);
-      memcpy (cur_abbrev->attrs, cur_attrs.data (),
-             cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
+      if (!cur_attrs.empty ())
+       memcpy (cur_abbrev->attrs, cur_attrs.data (),
+               cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
 
       abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
 
index 1d27971f5cc9cb5b0be7f91ed730fe26ddfa5799..86233e8d0ef5a21d01d082391ad95a50a04dd52f 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-31  Tom Tromey  <tromey@adacore.com>
+
+       * btrace-common.cc (btrace_data_append): Conditionally call
+       memcpy.
+
 2020-03-27  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * create-version.sh: Resolve issues highlighted by shellcheck.
index 7d4f6424c8286f72ce705e2cc4f549f0548dce21..e8b24db7d53607f92a010100ad22f2cd52e07d5b 100644 (file)
@@ -173,7 +173,8 @@ btrace_data_append (struct btrace_data *dst,
            size = src->variant.pt.size + dst->variant.pt.size;
            data = (gdb_byte *) xmalloc (size);
 
-           memcpy (data, dst->variant.pt.data, dst->variant.pt.size);
+           if (dst->variant.pt.size > 0)
+             memcpy (data, dst->variant.pt.data, dst->variant.pt.size);
            memcpy (data + dst->variant.pt.size, src->variant.pt.data,
                    src->variant.pt.size);
 
This page took 0.029539 seconds and 4 git commands to generate.