mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: ir: fix warning: ‘%s’ directive output may be truncated
@ 2019-01-31 19:43 Shuah Khan
  2019-02-04 20:47 ` Sean Young
  0 siblings, 1 reply; 2+ messages in thread
From: Shuah Khan @ 2019-01-31 19:43 UTC (permalink / raw)
  To: shuah, sean; +Cc: linux-kselftest, linux-kernel

Fix the following warning by sizing the buffer to max. of sysfs
path max. size + d_name max. size.

gcc -Wall -O2 -I../../../include/uapi ir_loopback.c  -o ../tools/testing/selftests/ir/ir_loopback
ir_loopback.c: In function ‘lirc_open’:
ir_loopback.c:71:37: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 95 [-Wformat-truncation=]
    snprintf(buf, sizeof(buf), "/dev/%s", dent->d_name);
                                     ^~
In file included from /usr/include/stdio.h:862:0,
                 from ir_loopback.c:14:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 6 and 261 bytes into a destination of size 100
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Shuah Khan <shuah@kernel.org>
---
 tools/testing/selftests/ir/ir_loopback.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/ir/ir_loopback.c b/tools/testing/selftests/ir/ir_loopback.c
index 858c19caf224..8cdf1b89ac9c 100644
--- a/tools/testing/selftests/ir/ir_loopback.c
+++ b/tools/testing/selftests/ir/ir_loopback.c
@@ -27,6 +27,8 @@
 
 #define TEST_SCANCODES	10
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define SYSFS_PATH_MAX 256
+#define DNAME_PATH_MAX 256
 
 static const struct {
 	enum rc_proto proto;
@@ -56,7 +58,7 @@ static const struct {
 int lirc_open(const char *rc)
 {
 	struct dirent *dent;
-	char buf[100];
+	char buf[SYSFS_PATH_MAX + DNAME_PATH_MAX];
 	DIR *d;
 	int fd;
 
-- 
2.17.1


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

* Re: [PATCH] selftests: ir: fix warning: ‘%s’ directive output may be truncated
  2019-01-31 19:43 [PATCH] selftests: ir: fix warning: ‘%s’ directive output may be truncated Shuah Khan
@ 2019-02-04 20:47 ` Sean Young
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Young @ 2019-02-04 20:47 UTC (permalink / raw)
  To: Shuah Khan; +Cc: linux-kselftest, linux-kernel

On Thu, Jan 31, 2019 at 12:43:12PM -0700, Shuah Khan wrote:
> Fix the following warning by sizing the buffer to max. of sysfs
> path max. size + d_name max. size.
> 
> gcc -Wall -O2 -I../../../include/uapi ir_loopback.c  -o ../tools/testing/selftests/ir/ir_loopback
> ir_loopback.c: In function ‘lirc_open’:
> ir_loopback.c:71:37: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 95 [-Wformat-truncation=]
>     snprintf(buf, sizeof(buf), "/dev/%s", dent->d_name);
>                                      ^~
> In file included from /usr/include/stdio.h:862:0,
>                  from ir_loopback.c:14:
> /usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 6 and 261 bytes into a destination of size 100
>    return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         __bos (__s), __fmt, __va_arg_pack ());
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Shuah Khan <shuah@kernel.org>

Thank you for catching and fixing these. For all three patches:

Acked-by: Sean Young <sean@mess.org>

> ---
>  tools/testing/selftests/ir/ir_loopback.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/ir/ir_loopback.c b/tools/testing/selftests/ir/ir_loopback.c
> index 858c19caf224..8cdf1b89ac9c 100644
> --- a/tools/testing/selftests/ir/ir_loopback.c
> +++ b/tools/testing/selftests/ir/ir_loopback.c
> @@ -27,6 +27,8 @@
>  
>  #define TEST_SCANCODES	10
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +#define SYSFS_PATH_MAX 256
> +#define DNAME_PATH_MAX 256
>  
>  static const struct {
>  	enum rc_proto proto;
> @@ -56,7 +58,7 @@ static const struct {
>  int lirc_open(const char *rc)
>  {
>  	struct dirent *dent;
> -	char buf[100];
> +	char buf[SYSFS_PATH_MAX + DNAME_PATH_MAX];
>  	DIR *d;
>  	int fd;
>  
> -- 
> 2.17.1

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

end of thread, other threads:[~2019-02-04 20:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31 19:43 [PATCH] selftests: ir: fix warning: ‘%s’ directive output may be truncated Shuah Khan
2019-02-04 20:47 ` Sean Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®