瀏覽代碼

[build] Do not apply WORKAROUND_CFLAGS for host compiler

The WORKAROUND_CFLAGS list is constructed based on running tests on
the target compiler, and the results may not be valid for the host
compiler.

The only relevant workaround required for the host compiler is
-Wno-stringop-truncation, which is needed to avoid a spurious compiler
warning for a totally correct usage of strncpy() in util/elf2efi.c.

Duplicating the workaround tests for the host compiler is messy, as is
conditionally applying __attribute__((nonstring)).  Fix instead by
disapplying WORKAROUND_CFLAGS for the host compiler, and using
memcpy() with an explicitly calculated length instead of strncpy() in
util/elf2efi.c.

Reported-by: Ignat Korchagin <ignat@cloudflare.com>
Reported-by: Christopher Clark <christopher.w.clark@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 5 年之前
父節點
當前提交
a4f8c6e31f
共有 2 個檔案被更改,包括 6 行新增2 行删除
  1. 1
    1
      src/Makefile.housekeeping
  2. 5
    1
      src/util/elf2efi.c

+ 1
- 1
src/Makefile.housekeeping 查看文件

@@ -454,7 +454,7 @@ endif
454 454
 CFLAGS		+= $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
455 455
 ASFLAGS		+= $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
456 456
 LDFLAGS		+= $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
457
-HOST_CFLAGS	+= $(WORKAROUND_CFLAGS) -O2 -g
457
+HOST_CFLAGS	+= -O2 -g
458 458
 
459 459
 # Inhibit -Werror if NO_WERROR is specified on make command line
460 460
 #

+ 5
- 1
src/util/elf2efi.c 查看文件

@@ -458,6 +458,7 @@ static struct pe_section * process_section ( struct elf_file *elf,
458 458
 					     struct pe_header *pe_header ) {
459 459
 	struct pe_section *new;
460 460
 	const char *name;
461
+	size_t name_len;
461 462
 	size_t section_memsz;
462 463
 	size_t section_filesz;
463 464
 	unsigned long code_start;
@@ -494,7 +495,10 @@ static struct pe_section * process_section ( struct elf_file *elf,
494 495
 	memset ( new, 0, sizeof ( *new ) + section_filesz );
495 496
 
496 497
 	/* Fill in section header details */
497
-	strncpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) );
498
+	name_len = strlen ( name );
499
+	if ( name_len > sizeof ( new->hdr.Name ) )
500
+		name_len = sizeof ( new->hdr.Name );
501
+	memcpy ( new->hdr.Name, name, name_len );
498 502
 	new->hdr.Misc.VirtualSize = section_memsz;
499 503
 	new->hdr.VirtualAddress = shdr->sh_addr;
500 504
 	new->hdr.SizeOfRawData = section_filesz;

Loading…
取消
儲存