All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] tools: solve gcc 10 compilation issues
@ 2020-10-05 16:02 Bertrand Marquis
  2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
  2020-10-05 16:02 ` [PATCH 2/2] tool/libx: Fix libxenlight gcc warning Bertrand Marquis
  0 siblings, 2 replies; 9+ messages in thread
From: Bertrand Marquis @ 2020-10-05 16:02 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Ian Jackson, Wei Liu, Anthony PERARD

Solve various issues in tools when compiling using a gcc version 10.0 or
greater.

Bertrand Marquis (2):
  tools: use memcpy instead of strncpy in getBridge
  tool/libx: Fix libxenlight gcc warning

 tools/libs/stat/xenstat_linux.c | 9 +++++++--
 tools/libxl/libxl_mem.c         | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

-- 
2.17.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-05 16:02 [PATCH 0/2] tools: solve gcc 10 compilation issues Bertrand Marquis
@ 2020-10-05 16:02 ` Bertrand Marquis
  2020-10-05 16:42   ` Wei Liu
  2020-10-06  4:34   ` Jürgen Groß
  2020-10-05 16:02 ` [PATCH 2/2] tool/libx: Fix libxenlight gcc warning Bertrand Marquis
  1 sibling, 2 replies; 9+ messages in thread
From: Bertrand Marquis @ 2020-10-05 16:02 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Ian Jackson, Wei Liu

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@arm.com>
---
 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);
 					result[resultLen - 1] = 0;
 				}
 		}
@@ -264,7 +269,7 @@ int xenstat_collect_networks(xenstat_node * node)
 {
 	/* Helper variables for parseNetDevLine() function defined above */
 	int i;
-	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
+	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
 	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
 
 	struct priv_data *priv = get_priv_data(node->handle);
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] tool/libx: Fix libxenlight gcc warning
  2020-10-05 16:02 [PATCH 0/2] tools: solve gcc 10 compilation issues Bertrand Marquis
  2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
@ 2020-10-05 16:02 ` Bertrand Marquis
  2020-10-05 16:57   ` Wei Liu
  1 sibling, 1 reply; 9+ messages in thread
From: Bertrand Marquis @ 2020-10-05 16:02 UTC (permalink / raw)
  To: xen-devel; +Cc: jgross, Ian Jackson, Wei Liu, Anthony PERARD

Fix gcc10 compilation warning about uninitialized variable by setting
it to 0.

Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
 tools/libxl/libxl_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_mem.c b/tools/libxl/libxl_mem.c
index e52a9624ea..c739d00f39 100644
--- a/tools/libxl/libxl_mem.c
+++ b/tools/libxl/libxl_mem.c
@@ -562,7 +562,7 @@ out:
 
 int libxl_get_free_memory_0x040700(libxl_ctx *ctx, uint32_t *memkb)
 {
-    uint64_t my_memkb;
+    uint64_t my_memkb = 0;
     int rc;
 
     rc = libxl_get_free_memory(ctx, &my_memkb);
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
@ 2020-10-05 16:42   ` Wei Liu
  2020-10-06  4:34   ` Jürgen Groß
  1 sibling, 0 replies; 9+ messages in thread
From: Wei Liu @ 2020-10-05 16:42 UTC (permalink / raw)
  To: Bertrand Marquis; +Cc: xen-devel, jgross, Ian Jackson, Wei Liu

On Mon, Oct 05, 2020 at 05:02:48PM +0100, 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@arm.com>

Juergen, are you happy with this change? I have not followed closely the
discussion on #xendevel.

> ---
>  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);
>  					result[resultLen - 1] = 0;
>  				}
>  		}
> @@ -264,7 +269,7 @@ int xenstat_collect_networks(xenstat_node * node)
>  {
>  	/* Helper variables for parseNetDevLine() function defined above */
>  	int i;
> -	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
> +	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
>  	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
>  
>  	struct priv_data *priv = get_priv_data(node->handle);
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] tool/libx: Fix libxenlight gcc warning
  2020-10-05 16:02 ` [PATCH 2/2] tool/libx: Fix libxenlight gcc warning Bertrand Marquis
@ 2020-10-05 16:57   ` Wei Liu
  0 siblings, 0 replies; 9+ messages in thread
From: Wei Liu @ 2020-10-05 16:57 UTC (permalink / raw)
  To: Bertrand Marquis; +Cc: xen-devel, jgross, Ian Jackson, Wei Liu, Anthony PERARD

On Mon, Oct 05, 2020 at 05:02:49PM +0100, Bertrand Marquis wrote:
> Fix gcc10 compilation warning about uninitialized variable by setting
> it to 0.
> 
> Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>

Acked-by: Wei Liu <wl@xen.org>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
  2020-10-05 16:42   ` Wei Liu
@ 2020-10-06  4:34   ` Jürgen Groß
  2020-10-06  7:51     ` Bertrand Marquis
  1 sibling, 1 reply; 9+ messages in thread
From: Jürgen Groß @ 2020-10-06  4:34 UTC (permalink / raw)
  To: Bertrand Marquis, xen-devel; +Cc: Ian Jackson, Wei Liu

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@arm.com>
> ---
>   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.


Juergen


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-06  4:34   ` Jürgen Groß
@ 2020-10-06  7:51     ` Bertrand Marquis
  2020-10-06  8:19       ` Jürgen Groß
  0 siblings, 1 reply; 9+ messages in thread
From: Bertrand Marquis @ 2020-10-06  7:51 UTC (permalink / raw)
  To: Jürgen Groß; +Cc: open list:X86, Ian Jackson, Wei Liu



> On 6 Oct 2020, at 05:34, Jürgen Groß <jgross@suse.com> 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@arm.com>
>> ---
>>  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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-06  7:51     ` Bertrand Marquis
@ 2020-10-06  8:19       ` Jürgen Groß
  2020-10-06 15:46         ` Bertrand Marquis
  0 siblings, 1 reply; 9+ messages in thread
From: Jürgen Groß @ 2020-10-06  8:19 UTC (permalink / raw)
  To: Bertrand Marquis; +Cc: open list:X86, Ian Jackson, Wei Liu

On 06.10.20 09:51, Bertrand Marquis wrote:
> 
> 
>> On 6 Oct 2020, at 05:34, Jürgen Groß <jgross@suse.com> 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@arm.com>
>>> ---
>>>   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.

Hmm, maybe you should use

min(strnlen(de->d_name, NAME_MAX), resultLen - 1)

for the case that de->d_name is near the end of a page, as otherwise
you could try to copy unallocated space.


Juergen


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
  2020-10-06  8:19       ` Jürgen Groß
@ 2020-10-06 15:46         ` Bertrand Marquis
  0 siblings, 0 replies; 9+ messages in thread
From: Bertrand Marquis @ 2020-10-06 15:46 UTC (permalink / raw)
  To: Jürgen Groß; +Cc: open list:X86, Ian Jackson, Wei Liu

Hi Jurgen,

> On 6 Oct 2020, at 09:19, Jürgen Groß <jgross@suse.com> wrote:
> 
> On 06.10.20 09:51, Bertrand Marquis wrote:
>>> On 6 Oct 2020, at 05:34, Jürgen Groß <jgross@suse.com> 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@arm.com>
>>>> ---
>>>>  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.
> 
> Hmm, maybe you should use
> 
> min(strnlen(de->d_name, NAME_MAX), resultLen - 1)
> 
> for the case that de->d_name is near the end of a page, as otherwise
> you could try to copy unallocated space.
> 

Agree, I will do that.

Cheers
Bertrand


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-06 15:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 16:02 [PATCH 0/2] tools: solve gcc 10 compilation issues Bertrand Marquis
2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
2020-10-05 16:42   ` Wei Liu
2020-10-06  4:34   ` Jürgen Groß
2020-10-06  7:51     ` Bertrand Marquis
2020-10-06  8:19       ` Jürgen Groß
2020-10-06 15:46         ` Bertrand Marquis
2020-10-05 16:02 ` [PATCH 2/2] tool/libx: Fix libxenlight gcc warning Bertrand Marquis
2020-10-05 16:57   ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.