[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
- To: Jürgen Groß <jgross@xxxxxxxx>
- From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
- Date: Tue, 6 Oct 2020 07:51:14 +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=8LRCBCTu8g9BZ2k5WA08aaKL1PgpqMaRSCOJp7SOPIo=; b=FKRU4vQ13wTDaKEaQQmEfBsej91RVw8qQRVJ9Lv4yDFF4OukA7gY1lU5DAunKQCVZWRiVlHbNa3OYuTI9jUgr4nGywC7NqLQ3RK0VU4d3pGfEFcnxEwir82PLUL3x2Q+cycV8IVzoF8YmTO4Tmc3xFOZhzPPubzQG0fHfxUpRYYNbq38yMP8XKRMU9B5q3VYjzqYut3pSHAJTv8Hej9d5pOHUsCuOfZPq8slrdUy9fPYHEuVV3J7WzXobXRDC87fBMygNDqatBjjoFvJLvuPkwenm/bmfK5Gm9RIQpWzKThwnAIQ2VgI6EZB3HFWryzsidFbG/L0br/I2E6sC30/0Q==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aOGh8Rg77IySt8DI+37bOFRKcfS3AJj2yA/d8raBGNIn9r4NEiJR9OqsVolr+khaRM2pZfWt7Ufocv5zyEVsW0OwAU9EwAcyoQSX/45nOkEHizuQFA4EI52uUl5UZa/EJ0cmwxQCTpMGSodqjbhQfEv9r+KAmXXFeHCD6YSfxZt4zyH7BsxOQbMIh8Pjqh+dyiazplFtA6naso0/G3Ag5UrsBoUiGoJcnxzDPFbvKH7kM7o4mrFJQlOERxAt1qPtE3lFLrR8GE2QZzZVP6kizEdzof+qf6V1f3l4ORBB0A7a9TJwsu4qyGy1BoAaIsHBC5aQw+30BS1+RBfEGwG5xg==
- Authentication-results-original: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=arm.com;
- Cc: "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Tue, 06 Oct 2020 07:51:48 +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: AQHWmzF2iz7tdPrAmU+VUEf6Gggal6mJ/YIAgAA3CAA=
- Thread-topic: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
> On 6 Oct 2020, at 05:34, Jürgen Groß <jgross@xxxxxxxx> wrote:
>
> On 05.10.20 18:02, Bertrand Marquis wrote:
>> Use memcpy in getBridge to prevent gcc warnings about truncated
>> strings. We know that we might truncate it, so the gcc warning
>> here is wrong.
>> Revert previous change changing buffer sizes as bigger buffers
>> are not needed.
>> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
>> ---
>> tools/libs/stat/xenstat_linux.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>> diff --git a/tools/libs/stat/xenstat_linux.c
>> b/tools/libs/stat/xenstat_linux.c
>> index d2ee6fda64..1db35c604c 100644
>> --- a/tools/libs/stat/xenstat_linux.c
>> +++ b/tools/libs/stat/xenstat_linux.c
>> @@ -78,7 +78,12 @@ static void getBridge(char *excludeName, char *result,
>> size_t resultLen)
>> sprintf(tmp, "/sys/class/net/%s/bridge",
>> de->d_name);
>> if (access(tmp, F_OK) == 0) {
>> - strncpy(result, de->d_name, resultLen);
>> + /*
>> + * Do not use strncpy to prevent
>> compiler warning with
>> + * gcc >= 10.0
>> + * If de->d_name is longer then
>> resultLen we truncate it
>> + */
>> + memcpy(result, de->d_name, resultLen -
>> 1);
>
> I think you want min(NAME_MAX, resultLen - 1) for the length.
true, I will fix that and send a v2.
Cheers
Bertrand
|