[ipxe-devel] [PATCH] [efi] Use memcpy to handle efi header name

Bernhard M. Wiedemann bwiedemann at suse.de
Mon Jun 18 11:43:30 UTC 2018


strncpy will copy 8 chars into a buffer of size 8
which does not leave space for the terminating null byte,
thus gcc8 failed compilation with

  In function 'process_section',
      inlined from 'elf2pe.isra.4' at util/elf2efi.c:913:25:
  util/elf2efi.c:497:2: error: 'strncpy' specified bound 8 equals destination size [-Werror=stringop-truncation]

It seems hdr.Name is not supposed to be null-terminated,
so memcpy is more appropriate.

Signed-off-by: Bernhard M. Wiedemann <bwiedemann at suse.de>
---
 src/util/elf2efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 6718df77..de3c9246 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -494,7 +494,7 @@ static struct pe_section * process_section ( struct elf_file *elf,
 	memset ( new, 0, sizeof ( *new ) + section_filesz );
 
 	/* Fill in section header details */
-	strncpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) );
+	memcpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) );
 	new->hdr.Misc.VirtualSize = section_memsz;
 	new->hdr.VirtualAddress = shdr->sh_addr;
 	new->hdr.SizeOfRawData = section_filesz;
-- 
2.13.7




More information about the ipxe-devel mailing list