Skip to content

Commit

Permalink
Don't pass NULL to memcpy in gdb
Browse files Browse the repository at this point in the history
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  <[email protected]>

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

gdbsupport/ChangeLog
2020-03-31  Tom Tromey  <[email protected]>

	* btrace-common.cc (btrace_data_append): Conditionally call
	memcpy.
  • Loading branch information
tromey committed Mar 31, 2020
1 parent 16b0db7 commit af62665
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions gdb/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-03-31 Tom Tromey <[email protected]>

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

2020-03-30 Nelson Chu <[email protected]>

* features/riscv/32bit-csr.xml: Regenerated.
Expand Down
5 changes: 3 additions & 2 deletions gdb/dwarf2/abbrev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions gdbsupport/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-03-31 Tom Tromey <[email protected]>

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

2020-03-27 Andrew Burgess <[email protected]>

* create-version.sh: Resolve issues highlighted by shellcheck.
Expand Down
3 changes: 2 additions & 1 deletion gdbsupport/btrace-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit af62665

Please sign in to comment.