From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 75D783858402; Fri, 26 Apr 2024 12:23:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75D783858402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1714134237; bh=WCRbPjyrILzuQAL8EKC00mLa35KbQrCBm4WYklfp6QU=; h=From:To:Subject:Date:From; b=wA5zR5XRFcqOene6NXoVWKx6OCbRCsdAykxGUAUErk/dZuCEBRLAq30IGXDU3SixW z4ih6fWgU43bN4hMKm957lc1OHML2iapvikO9byPjEYorWE8bfYHCQjjA/6199ZCby tUJGE1N5gYixXHhcQLgUBrQwrTcntq2g9leYDGQM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: binutils-cvs@sourceware.org Subject: [binutils-gdb] objcopy: check input flavor before setting PE/COFF section alignment X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: cd0dbe767775fdbfdc875a14f9080fdea0841c92 X-Git-Newrev: 6fde04116b4b835fa9ec3b3497fcac4e4a0637e2 Message-Id: <20240426122357.75D783858402@sourceware.org> Date: Fri, 26 Apr 2024 12:23:57 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6fde04116b4b= 835fa9ec3b3497fcac4e4a0637e2 commit 6fde04116b4b835fa9ec3b3497fcac4e4a0637e2 Author: Jan Beulich Date: Fri Apr 26 14:23:14 2024 +0200 objcopy: check input flavor before setting PE/COFF section alignment =20 coff_section_data() and elf_section_data() use the same underlying field. The pointer being non-NULL therefore isn't sufficient to know that pei_section_data() can validly be used on the incoming object. Apparently in 64-bit-host builds the resulting memory corruption is benign, whereas in 32-bit-host builds a segmentation fault occurs upon de-referencing pei_section_data()'s return value. Diff: --- binutils/objcopy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index e8ca1374935..26f9d4a0f26 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4317,6 +4317,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obf= darg) if (p !=3D NULL) alignment =3D p->alignment; else if (pe_section_alignment !=3D (bfd_vma) -1 + && bfd_get_flavour (ibfd) =3D=3D bfd_target_coff_flavour && bfd_get_flavour (obfd) =3D=3D bfd_target_coff_flavour) { alignment =3D power_of_two (pe_section_alignment);