[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3] tools/libs/stat: fix broken build


  • To: Jürgen Groß <jgross@xxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Fri, 2 Oct 2020 10:12:22 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xM2AM7ZoE/80Nc9Pbia61OrulRWXjE18A6I508xxGRA=; b=TS8Ww+Tdd1CzwmYHrvFVwaSZDYcNAdTvavfX33v6IlbHrSmfI8lPL3bqcqwvW4hM6Uays9QlOka0U+N8y45O5Z647oYbSa65Xj1zRm8T8M45Dj1+nRL2zVqvjh7v+gFC8Lkmbz6CJaT3cZ61XzUFZVl5Ngmhvuug0Xg8oheZtiyng9wxQzmy/jjvrO8OS9Tu8wfuGcxjF86wlQJ27BgKALQbO+7wew3NWyKmYUH5/aS4FdGAqAz7tETwZmgSvM/ru4Ha8B7LfJrHuE9APkSSe64xG8drOgjUg5unp+N/auebKngK+IfmFU5TF7Ih27ZCahV+UsM+D130YmpZgaoMzA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NwMKlqNfS1Qf2g3MwXhKbTeWFdtG7BEdpZ6LEqsQESGCrtOijtuvcb0MH8wufWiHgt+X0LbR4ezCEoc9EJQDt0pCtWlEcnteoYyBLYhUAUc6ffHNcW1S3/ehogRRpwOq53Ox8Bdxxe/Iin6cHdRILwNSM0DiCTwzilvl/mPFBBpc69QSHkfkPN86F2YHoWctjPY1VvnJ3kCm2ox//zHXIk/FSJ3GKJCv9Zgb+PBrqasb8EIasG8VrcoNCO+b+TegFYmpxiUwULk2Pz9IyL8UfIgZkLNiQ5CSVeMwSVnkf2NEYHbdukAGmY1EerGqewzB+Wsa3uJo6AGSv7K9iWDCnQ==
  • Authentication-results-original: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=arm.com;
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 02 Oct 2020 10:13:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHWiQYtlvZlYAgRJ0WaZGJ4HThwo6ln+foAgBsWa4CAAMywgIAAGQiAgAAIpgCAAAJuAIAABycAgAAuo4A=
  • Thread-topic: [PATCH v3] tools/libs/stat: fix broken build

Hi,

> On 2 Oct 2020, at 08:25, Jürgen Groß <jgross@xxxxxxxx> wrote:
> 
> On 02.10.20 08:59, Jan Beulich wrote:
>> On 02.10.2020 08:51, Jürgen Groß wrote:
>>> On 02.10.20 08:20, Jan Beulich wrote:
>>>> On 02.10.2020 06:50, Jürgen Groß wrote:
>>>>> On 01.10.20 18:38, Bertrand Marquis wrote:
>>>>>> Hi Juergen,
>>>>>> 
>>>>>>> On 14 Sep 2020, at 11:58, Bertrand Marquis <bertrand.marquis@xxxxxxx> 
>>>>>>> wrote:
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> On 12 Sep 2020, at 14:08, Juergen Gross <jgross@xxxxxxxx> wrote:
>>>>>>>> 
>>>>>>>> Making getBridge() static triggered a build error with some gcc 
>>>>>>>> versions:
>>>>>>>> 
>>>>>>>> error: 'strncpy' output may be truncated copying 15 bytes from a 
>>>>>>>> string of
>>>>>>>> length 255 [-Werror=stringop-truncation]
>>>>>>>> 
>>>>>>>> Fix that by using a buffer with 256 bytes instead.
>>>>>>>> 
>>>>>>>> Fixes: 6d0ec053907794 ("tools: split libxenstat into new 
>>>>>>>> tools/libs/stat directory")
>>>>>>>> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
>>>>>>> Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
>>>>>> 
>>>>>> Sorry i have to come back on this one.
>>>>>> 
>>>>>> I still see an error compiling with Yocto on this one:
>>>>>> |     inlined from 'xenstat_collect_networks' at xenstat_linux.c:306:2:
>>>>>> | xenstat_linux.c:81:6: error: 'strncpy' output may be truncated copying 
>>>>>> 255 bytes from a string of length 255 [-Werror=stringop-truncation]
>>>>>> |    81 |      strncpy(result, de->d_name, resultLen);
>>>>>> |       |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>> 
>>>>>> To solve it, I need to define devBridge[257] as devNoBrideg.
>>>>> 
>>>>> IMHO this is a real compiler error.
>>>>> 
>>>>> de->d_name is an array of 256 bytes, so doing strncpy() from that to
>>>>> another array of 256 bytes with a length of 256 won't truncate anything.
>>>> 
>>>> That's a matter of how you look at it, I think: If the original array
>>>> doesn't hold a nul-terminated string, the destination array won't
>>>> either, yet the common goal of strncpy() is to yield a properly nul-
>>>> terminated string. IOW the warning may be since the standard even has
>>>> a specific foot note to point out this possible pitfall.
>>> 
>>> If the source doesn't hold a nul-terminated string there will still be
>>> 256 bytes copied, so there is no truncation done during strncpy().
>>> 
>>> In fact there is no way to use strncpy() in a safe way on a fixed sized
>>> source array with the above semantics: either the target is larger than
>>> the source and length is at least sizeof(source) + 1, resulting in a
>>> possible read beyond the end of source, or the target is the same length
>>> leading to the error.
>> I agree with all of what you say, but I can also see why said foot note
>> alone may have motivated the emission of the warning.
> 
> The motivation can be explained, yes, but it is wrong. strncpy() is not
> limited to source arrays of unknown length. So this warning is making
> strncpy() unusable for fixed sized source strings and -Werror. And that
> is nothing a compiler should be allowed to do, hence a compiler bug.

I do agree that in this case the compiler is doing to much.

We could also choose to turn off the warning either using pragma (which
i really do not like) or by adding a cflag for this specific file (but this 
might
hit us later in other places).

All in all this currently makes Xen master and staging not possible to
compile with Yocto so we need to find a solution as this will also
come in any distribution using a new compiler,

Cheers
Bertrand


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.