Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
mcb30 committed Jul 22, 2019
1 parent 1dd56db commit a4f8c6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.housekeeping
Expand Up @@ -454,7 +454,7 @@ endif
CFLAGS += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
ASFLAGS += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
LDFLAGS += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
HOST_CFLAGS += $(WORKAROUND_CFLAGS) -O2 -g
HOST_CFLAGS += -O2 -g

# Inhibit -Werror if NO_WERROR is specified on make command line
#
Expand Down
6 changes: 5 additions & 1 deletion src/util/elf2efi.c
Expand Up @@ -458,6 +458,7 @@ static struct pe_section * process_section ( struct elf_file *elf,
struct pe_header *pe_header ) {
struct pe_section *new;
const char *name;
size_t name_len;
size_t section_memsz;
size_t section_filesz;
unsigned long code_start;
Expand Down Expand Up @@ -494,7 +495,10 @@ 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 ) );
name_len = strlen ( name );
if ( name_len > sizeof ( new->hdr.Name ) )
name_len = sizeof ( new->hdr.Name );
memcpy ( new->hdr.Name, name, name_len );
new->hdr.Misc.VirtualSize = section_memsz;
new->hdr.VirtualAddress = shdr->sh_addr;
new->hdr.SizeOfRawData = section_filesz;
Expand Down

0 comments on commit a4f8c6e

Please sign in to comment.