From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id E56123858291; Mon, 26 Sep 2022 09:55:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E56123858291 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] PR29613, use of uninitialized value in objcopy X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: c21736aed1d4877e090df60362413669dbdc391d X-Git-Newrev: c7afb87bea33c27c7e669b94275fb8c22d6f43bc Message-Id: <20220926095557.E56123858291@sourceware.org> Date: Mon, 26 Sep 2022 09:55:57 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Sep 2022 09:55:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc7afb87bea33= c27c7e669b94275fb8c22d6f43bc commit c7afb87bea33c27c7e669b94275fb8c22d6f43bc Author: Alan Modra Date: Mon Sep 26 18:25:24 2022 +0930 PR29613, use of uninitialized value in objcopy =20 PR 29613 * elf.c (_bfd_elf_write_secondary_reloc_section): Trim sh_size back to relocs written. Use better types for vars. Diff: --- bfd/elf.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 9a0bc1d2740..396b56db024 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -13482,9 +13482,9 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) { asymbol * last_sym; int last_sym_idx; - unsigned int reloc_count; - unsigned int idx; - unsigned int entsize; + size_t reloc_count; + size_t idx; + bfd_size_type entsize; arelent * src_irel; bfd_byte * dst_rela; =20 @@ -13525,7 +13525,8 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) } =20 reloc_count =3D hdr->sh_size / entsize; - if (reloc_count <=3D 0) + hdr->sh_size =3D entsize * reloc_count; + if (reloc_count =3D=3D 0) { _bfd_error_handler /* xgettext:c-format */ @@ -13572,7 +13573,7 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) { _bfd_error_handler /* xgettext:c-format */ - (_("%pB(%pA): error: reloc table entry %u is empty"), + (_("%pB(%pA): error: reloc table entry %zu is empty"), abfd, relsec, idx); bfd_set_error (bfd_error_bad_value); result =3D false; @@ -13597,7 +13598,7 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) { _bfd_error_handler /* xgettext:c-format */ - (_("%pB(%pA): error: secondary reloc %u" + (_("%pB(%pA): error: secondary reloc %zu" " references a missing symbol"), abfd, relsec, idx); bfd_set_error (bfd_error_bad_value); @@ -13615,7 +13616,7 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) { _bfd_error_handler /* xgettext:c-format */ - (_("%pB(%pA): error: secondary reloc %u" + (_("%pB(%pA): error: secondary reloc %zu" " references a deleted symbol"), abfd, relsec, idx); bfd_set_error (bfd_error_bad_value); @@ -13629,7 +13630,7 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, = asection *sec) { _bfd_error_handler /* xgettext:c-format */ - (_("%pB(%pA): error: secondary reloc %u" + (_("%pB(%pA): error: secondary reloc %zu" " is of an unknown type"), abfd, relsec, idx); bfd_set_error (bfd_error_bad_value);