[binutils-gdb] PR 34353 objcopy: null-pointer dereference bfd/section.c:1433
Alan Modra
amodra@sourceware.org
Tue Jul 7 01:13:01 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=64ca9aa24218cee8b31c4dc47694369da67b1acd
commit 64ca9aa24218cee8b31c4dc47694369da67b1acd
Author: Alan Modra <amodra@gmail.com>
Date: Mon Jul 6 11:26:24 2026 +0930
PR 34353 objcopy: null-pointer dereference bfd/section.c:1433
objcopy --update-section specifying a SHT_GROUP section hits a case
where output_section is NULL.
* objcopy.c (copy_object): Don't segfault when update_sections
output_section is NULL. Remove the "not found" part of
existing error so this message can be used.
* testsuite/binutils-all/update-section.exp: Update to suit.
Diff:
---
binutils/objcopy.c | 6 +++---
binutils/testsuite/binutils-all/update-section.exp | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 89eb3f72dcd..4ab7e8997b5 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3072,13 +3072,13 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
pupdate = pupdate->next)
{
pupdate->section = bfd_get_section_by_name (ibfd, pupdate->name);
- if (pupdate->section == NULL)
+ if (pupdate->section == NULL
+ || (osec = pupdate->section->output_section) == NULL)
{
- non_fatal (_("error: %s not found, can't be updated"), pupdate->name);
+ non_fatal (_("error: %s can't be updated"), pupdate->name);
return false;
}
- osec = pupdate->section->output_section;
if (!bfd_set_section_size (osec, pupdate->size))
{
bfd_nonfatal_message (NULL, obfd, osec, NULL);
diff --git a/binutils/testsuite/binutils-all/update-section.exp b/binutils/testsuite/binutils-all/update-section.exp
index 273e1154ec9..3fd679b3cc7 100644
--- a/binutils/testsuite/binutils-all/update-section.exp
+++ b/binutils/testsuite/binutils-all/update-section.exp
@@ -111,7 +111,7 @@ do_compare update-1.o update-4.o
# Check that --update-section on an unknown section will fail.
if { ![do_objcopy update-2.o \
"--update-section .bar=tmpdir/dumped-contents" \
- "error: .bar not found, can't be updated"] } then {
+ "error: .bar can't be updated"] } then {
return
}
More information about the Binutils-cvs
mailing list