[ipxe-devel] [PATCH 1/1] [build] fix stringop truncation warning with GCC 8.x
Bruce Rogers
brogers at suse.com
Tue May 15 22:19:57 UTC 2018
>>> On 5/15/2018 at 3:58 PM, Christian Nilsson <nikize at gmail.com> wrote:
> On 15 May 2018 at 23:30, Christian Hesse <list at eworm.de> wrote:
>> From: Christian Hesse <mail at eworm.de>
>>
>> GCC 8.x gives a warning about stringop truncation:
>>
>> util/elf2efi.c:497:2: error: ‘strncpy’ specified bound 8 equals destination
>> size [-Werror=stringop-truncation]
>>
>> It assumes that strncpy() is intended to copy strings, which are NULL
>> terminated. We do copy fixed size memory regions, so use memcpy() instead.
>>
>> Signed-off-by: Christian Hesse <mail at eworm.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;
>
> Hi,
> Similar and other "fixes" have been suggested and discuessed, in this
> case see http://lists.ipxe.org/pipermail/ipxe-devel/2018-April/006144.html
>
> Suggested fix for the build:
> http://lists.ipxe.org/pipermail/ipxe-devel/2018-April/006146.html
> And used solution by Suse:
> http://lists.ipxe.org/pipermail/ipxe-devel/2018-May/006157.html
>
> Bruce did you find any issues using your first patch?
I really never "used" the first patch, so I can't say for what issues would occur.
I was only at the point of getting the qemu package (which also builds ipxe from
source) to build with the gcc 8 compiler.
Bruce
More information about the ipxe-devel
mailing list