[binutils-gdb] Don't write uninitialised data in .note.gnu.property

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7376294773866a66031f91dd3272669ef41d6b04

commit 7376294773866a66031f91dd3272669ef41d6b04
Author: Alan Modra <[email protected]>
Date:   Wed Apr 8 08:57:39 2026 +0930

    Don't write uninitialised data in .note.gnu.property
    
    Seen when running the binutils x86-64 pr23494 tests.
    _bfd_elf_convert_gnu_properties doesn't initialise its "contents"
    buffer, and elf_write_gnu_properties doesn't write to padding.
    Fix this by initialising the padding and then dispense with zeroing
    contents in _bfd_elf_link_setup_gnu_properties.
    
            * elf-properties.c (elf_write_gnu_properties): Init padding.
            (_bfd_elf_link_setup_gnu_properties): Don't init contents.

Diff:
---
 bfd/elf-properties.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index 988b7d0dd02..e0a830704fd 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -670,7 +670,12 @@ elf_write_gnu_properties (struct bfd_link_info *info,
       size += datasz;
 
       /* Align each property.  */
-      size = (size + (align_size - 1)) & ~ (align_size - 1);
+      datasz = -size & (align_size - 1);
+      if (datasz)
+	{
+	  memset (contents + size, 0, datasz);
+	  size += datasz;
+	}
     }
 }
 
@@ -933,7 +938,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
       /* Update .note.gnu.property section now.  */
       sec->size = size;
-      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
+      contents = bfd_alloc (first_pbfd, size);
 
       elf_write_gnu_properties (info, first_pbfd, contents, list, size,
 				align_size);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.