Browse Source

[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 4 years ago
parent
commit
a4f8c6e31f
2 changed files with 6 additions and 2 deletions
  1. 1
    1
      src/Makefile.housekeeping
  2. 5
    1
      src/util/elf2efi.c

+ 1
- 1
src/Makefile.housekeeping View File

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

+ 5
- 1
src/util/elf2efi.c View File

458
 					     struct pe_header *pe_header ) {
458
 					     struct pe_header *pe_header ) {
459
 	struct pe_section *new;
459
 	struct pe_section *new;
460
 	const char *name;
460
 	const char *name;
461
+	size_t name_len;
461
 	size_t section_memsz;
462
 	size_t section_memsz;
462
 	size_t section_filesz;
463
 	size_t section_filesz;
463
 	unsigned long code_start;
464
 	unsigned long code_start;
494
 	memset ( new, 0, sizeof ( *new ) + section_filesz );
495
 	memset ( new, 0, sizeof ( *new ) + section_filesz );
495
 
496
 
496
 	/* Fill in section header details */
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
 	new->hdr.Misc.VirtualSize = section_memsz;
502
 	new->hdr.Misc.VirtualSize = section_memsz;
499
 	new->hdr.VirtualAddress = shdr->sh_addr;
503
 	new->hdr.VirtualAddress = shdr->sh_addr;
500
 	new->hdr.SizeOfRawData = section_filesz;
504
 	new->hdr.SizeOfRawData = section_filesz;

Loading…
Cancel
Save