diff options
author | Tom Tromey <tromey@adacore.com> | 2020-03-31 07:29:53 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-03-31 07:29:53 -0600 |
commit | af62665e1339d970ab8ea3e3260dbdbde0009c2d (patch) | |
tree | 826edde9a32cce686cb46b1a89f7a341034a7d4b /gdbsupport | |
parent | 16b0db75af6b4b4d434aa84c74d58b7290e04143 (diff) | |
download | binutils-af62665e1339d970ab8ea3e3260dbdbde0009c2d.zip binutils-af62665e1339d970ab8ea3e3260dbdbde0009c2d.tar.gz binutils-af62665e1339d970ab8ea3e3260dbdbde0009c2d.tar.bz2 |
Don't pass NULL to memcpy in gdb
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.
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/ChangeLog | 5 | ||||
-rw-r--r-- | gdbsupport/btrace-common.cc | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 1d27971..86233e8 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -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. diff --git a/gdbsupport/btrace-common.cc b/gdbsupport/btrace-common.cc index 7d4f642..e8b24db 100644 --- a/gdbsupport/btrace-common.cc +++ b/gdbsupport/btrace-common.cc @@ -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); |