All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 14:46 ` Daniel P. Berrangé
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel P. Berrangé @ 2019-05-01 14:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Riku Voipio, Daniel P. Berrangé

In file included from /usr/include/string.h:494,
                 from include/qemu/osdep.h:101,
                 from linux-user/uname.c:20:
In function ‘strncpy’,
    inlined from ‘sys_uname’ at linux-user/uname.c:94:3:
/usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We don't care where the NUL terminator in the original uname
field was. It suffices to copy the entire original field and
simply force a NUL terminator at the end of the new field.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---

Changed in v2:

 - Always use sizeof() in preference to __NEW_UTS_LEN

 linux-user/uname.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/linux-user/uname.c b/linux-user/uname.c
index 313b79dbad..1c05f95387 100644
--- a/linux-user/uname.c
+++ b/linux-user/uname.c
@@ -72,9 +72,8 @@ const char *cpu_to_uname_machine(void *cpu_env)
 
 #define COPY_UTSNAME_FIELD(dest, src) \
   do { \
-      /* __NEW_UTS_LEN doesn't include terminating null */ \
-      (void) strncpy((dest), (src), __NEW_UTS_LEN); \
-      (dest)[__NEW_UTS_LEN] = '\0'; \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \
+      (dest)[sizeof(dest) - 1] = '\0'; \
   } while (0)
 
 int sys_uname(struct new_utsname *buf)
-- 
2.21.0

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

* [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 14:46 ` Daniel P. Berrangé
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel P. Berrangé @ 2019-05-01 14:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier

In file included from /usr/include/string.h:494,
                 from include/qemu/osdep.h:101,
                 from linux-user/uname.c:20:
In function ‘strncpy’,
    inlined from ‘sys_uname’ at linux-user/uname.c:94:3:
/usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We don't care where the NUL terminator in the original uname
field was. It suffices to copy the entire original field and
simply force a NUL terminator at the end of the new field.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---

Changed in v2:

 - Always use sizeof() in preference to __NEW_UTS_LEN

 linux-user/uname.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/linux-user/uname.c b/linux-user/uname.c
index 313b79dbad..1c05f95387 100644
--- a/linux-user/uname.c
+++ b/linux-user/uname.c
@@ -72,9 +72,8 @@ const char *cpu_to_uname_machine(void *cpu_env)
 
 #define COPY_UTSNAME_FIELD(dest, src) \
   do { \
-      /* __NEW_UTS_LEN doesn't include terminating null */ \
-      (void) strncpy((dest), (src), __NEW_UTS_LEN); \
-      (dest)[__NEW_UTS_LEN] = '\0'; \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \
+      (dest)[sizeof(dest) - 1] = '\0'; \
   } while (0)
 
 int sys_uname(struct new_utsname *buf)
-- 
2.21.0



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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 14:51   ` no-reply
  0 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2019-05-01 14:51 UTC (permalink / raw)
  To: berrange; +Cc: fam, qemu-devel, riku.voipio, laurent

Patchew URL: https://patchew.org/QEMU/20190501144646.4851-1-berrange@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190501144646.4851-1-berrange@redhat.com
Subject: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/20190501144646.4851-1-berrange@redhat.com -> patchew/20190501144646.4851-1-berrange@redhat.com
Switched to a new branch 'test'
c08b5ed306 linux-user: avoid string truncation warnings in uname field copying

=== OUTPUT BEGIN ===
ERROR: suspect code indent for conditional statements (2, 6)
#30: FILE: linux-user/uname.c:74:
   do { \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \

total: 1 errors, 0 warnings, 11 lines checked

Commit c08b5ed30674 (linux-user: avoid string truncation warnings in uname field copying) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190501144646.4851-1-berrange@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 14:51   ` no-reply
  0 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2019-05-01 14:51 UTC (permalink / raw)
  To: berrange; +Cc: fam, riku.voipio, qemu-devel, laurent

Patchew URL: https://patchew.org/QEMU/20190501144646.4851-1-berrange@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190501144646.4851-1-berrange@redhat.com
Subject: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/20190501144646.4851-1-berrange@redhat.com -> patchew/20190501144646.4851-1-berrange@redhat.com
Switched to a new branch 'test'
c08b5ed306 linux-user: avoid string truncation warnings in uname field copying

=== OUTPUT BEGIN ===
ERROR: suspect code indent for conditional statements (2, 6)
#30: FILE: linux-user/uname.c:74:
   do { \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \

total: 1 errors, 0 warnings, 11 lines checked

Commit c08b5ed30674 (linux-user: avoid string truncation warnings in uname field copying) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190501144646.4851-1-berrange@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
  2019-05-01 14:46 ` Daniel P. Berrangé
  (?)
  (?)
@ 2019-05-01 15:24 ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-05-01 15:24 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: Riku Voipio, Laurent Vivier

On 5/1/19 4:46 PM, Daniel P. Berrangé wrote:
> In file included from /usr/include/string.h:494,
>                  from include/qemu/osdep.h:101,
>                  from linux-user/uname.c:20:
> In function ‘strncpy’,
>     inlined from ‘sys_uname’ at linux-user/uname.c:94:3:
> /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
>   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> We don't care where the NUL terminator in the original uname
> field was. It suffices to copy the entire original field and
> simply force a NUL terminator at the end of the new field.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
> 
> Changed in v2:
> 
>  - Always use sizeof() in preference to __NEW_UTS_LEN
> 
>  linux-user/uname.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/uname.c b/linux-user/uname.c
> index 313b79dbad..1c05f95387 100644
> --- a/linux-user/uname.c
> +++ b/linux-user/uname.c
> @@ -72,9 +72,8 @@ const char *cpu_to_uname_machine(void *cpu_env)
>  
>  #define COPY_UTSNAME_FIELD(dest, src) \
>    do { \
> -      /* __NEW_UTS_LEN doesn't include terminating null */ \
> -      (void) strncpy((dest), (src), __NEW_UTS_LEN); \
> -      (dest)[__NEW_UTS_LEN] = '\0'; \
> +      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \
> +      (dest)[sizeof(dest) - 1] = '\0'; \
>    } while (0)
>  
>  int sys_uname(struct new_utsname *buf)
> 

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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 15:28   ` no-reply
  0 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2019-05-01 15:28 UTC (permalink / raw)
  To: berrange; +Cc: fam, qemu-devel, riku.voipio, laurent

Patchew URL: https://patchew.org/QEMU/20190501144646.4851-1-berrange@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190501144646.4851-1-berrange@redhat.com
Subject: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190501144646.4851-1-berrange@redhat.com -> patchew/20190501144646.4851-1-berrange@redhat.com
Switched to a new branch 'test'
b97fa7be34 linux-user: avoid string truncation warnings in uname field copying

=== OUTPUT BEGIN ===
ERROR: suspect code indent for conditional statements (2, 6)
#31: FILE: linux-user/uname.c:74:
   do { \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \

total: 1 errors, 0 warnings, 11 lines checked

Commit b97fa7be344e (linux-user: avoid string truncation warnings in uname field copying) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190501144646.4851-1-berrange@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
@ 2019-05-01 15:28   ` no-reply
  0 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2019-05-01 15:28 UTC (permalink / raw)
  To: berrange; +Cc: fam, riku.voipio, qemu-devel, laurent

Patchew URL: https://patchew.org/QEMU/20190501144646.4851-1-berrange@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190501144646.4851-1-berrange@redhat.com
Subject: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190501144646.4851-1-berrange@redhat.com -> patchew/20190501144646.4851-1-berrange@redhat.com
Switched to a new branch 'test'
b97fa7be34 linux-user: avoid string truncation warnings in uname field copying

=== OUTPUT BEGIN ===
ERROR: suspect code indent for conditional statements (2, 6)
#31: FILE: linux-user/uname.c:74:
   do { \
+      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \

total: 1 errors, 0 warnings, 11 lines checked

Commit b97fa7be344e (linux-user: avoid string truncation warnings in uname field copying) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190501144646.4851-1-berrange@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying
  2019-05-01 14:46 ` Daniel P. Berrangé
                   ` (3 preceding siblings ...)
  (?)
@ 2019-05-02  8:16 ` Laurent Vivier
  -1 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2019-05-02  8:16 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: Riku Voipio, Alistair Francis

On 01/05/2019 16:46, Daniel P. Berrangé wrote:
> In file included from /usr/include/string.h:494,
>                  from include/qemu/osdep.h:101,
>                  from linux-user/uname.c:20:
> In function ‘strncpy’,
>     inlined from ‘sys_uname’ at linux-user/uname.c:94:3:
> /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
>   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> We don't care where the NUL terminator in the original uname
> field was. It suffices to copy the entire original field and
> simply force a NUL terminator at the end of the new field.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> 
> Changed in v2:
> 
>  - Always use sizeof() in preference to __NEW_UTS_LEN
> 
>  linux-user/uname.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/uname.c b/linux-user/uname.c
> index 313b79dbad..1c05f95387 100644
> --- a/linux-user/uname.c
> +++ b/linux-user/uname.c
> @@ -72,9 +72,8 @@ const char *cpu_to_uname_machine(void *cpu_env)
>  
>  #define COPY_UTSNAME_FIELD(dest, src) \
>    do { \
> -      /* __NEW_UTS_LEN doesn't include terminating null */ \
> -      (void) strncpy((dest), (src), __NEW_UTS_LEN); \
> -      (dest)[__NEW_UTS_LEN] = '\0'; \
> +      memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \
> +      (dest)[sizeof(dest) - 1] = '\0'; \
>    } while (0)
>  
>  int sys_uname(struct new_utsname *buf)
> 

Applied to my linux-user branch.

Thanks,
Laurent

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

end of thread, other threads:[~2019-05-02  8:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 14:46 [Qemu-devel] [PATCH v2] linux-user: avoid string truncation warnings in uname field copying Daniel P. Berrangé
2019-05-01 14:46 ` Daniel P. Berrangé
2019-05-01 14:51 ` no-reply
2019-05-01 14:51   ` no-reply
2019-05-01 15:24 ` Philippe Mathieu-Daudé
2019-05-01 15:28 ` no-reply
2019-05-01 15:28   ` no-reply
2019-05-02  8:16 ` Laurent Vivier

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.