From 00bc5e68b2c02fd2b1daacc37850840498595fb0 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 26 Aug 2020 18:32:30 +0930 Subject: [PATCH] PR26478 UBSAN: mmo.c:2941 null pointer memcpy PR 26478 * mmo.c (mmo_write_symbols_and_terminator): Don't memcpy empty table. --- bfd/ChangeLog | 5 +++++ bfd/mmo.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3a85c3eb9a5..86fccfb79d9 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2020-08-26 Alan Modra + + PR 26478 + * mmo.c (mmo_write_symbols_and_terminator): Don't memcpy empty table. + 2020-08-26 Alan Modra PR 26475 diff --git a/bfd/mmo.c b/bfd/mmo.c index 5209736a505..92c51a4f637 100644 --- a/bfd/mmo.c +++ b/bfd/mmo.c @@ -2938,7 +2938,8 @@ mmo_write_symbols_and_terminator (bfd *abfd) if (table == NULL) return FALSE; - memcpy (table, orig_table, count * sizeof (asymbol *)); + if (count != 0) + memcpy (table, orig_table, count * sizeof (asymbol *)); /* Move :Main (if there is one) to the first position. This is necessary to get the same layout of the trie-tree when linking as -- 2.30.2