All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Cc: qemu-devel@nongnu.org, "Stefan Weil" <sw@weilnetz.de>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>
Subject: Re: [PATCH] tap-win32: fix format-truncation warning
Date: Wed, 23 Oct 2024 20:50:09 +0100	[thread overview]
Message-ID: <875xpilhu6.fsf@draig.linaro.org> (raw)
In-Reply-To: <20241023183009.1041419-1-pierrick.bouvier@linaro.org> (Pierrick Bouvier's message of "Wed, 23 Oct 2024 11:30:09 -0700")

Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:

> Simply increase destination buffer size so truncation can't happen.
>
> "cc" "-m64" "-Ilibcommon.a.p" "-Isubprojects/dtc/libfdt"
> "-I../subprojects/dtc/libfdt"
> "-ID:/a/_temp/msys64/mingw64/include/pixman-1"
> "-ID:/a/_temp/msys64/mingw64/include/glib-2.0"
> "-ID:/a/_temp/msys64/mingw64/lib/glib-2.0/include"
> "-ID:/a/_temp/msys64/mingw64/include/ncursesw"
> "-fdiagnostics-color=auto" "-Wall" "-Winvalid-pch" "-Werror"
> "-std=gnu11" "-O2" "-g" "-fstack-protector-strong" "-Wempty-body"
> "-Wendif-labels" "-Wexpansion-to-defined" "-Wformat-security"
> "-Wformat-y2k" "-Wignored-qualifiers" "-Wimplicit-fallthrough=2"
> "-Winit-self" "-Wmissing-format-attribute" "-Wmissing-prototypes"
> "-Wnested-externs" "-Wold-style-declaration" "-Wold-style-definition"
> "-Wredundant-decls" "-Wshadow=local" "-Wstrict-prototypes"
> "-Wtype-limits" "-Wundef" "-Wvla" "-Wwrite-strings"
> "-Wno-missing-include-dirs" "-Wno-psabi" "-Wno-shift-negative-value"
> "-iquote" "." "-iquote" "D:/a/qemu/qemu" "-iquote"
> "D:/a/qemu/qemu/include" "-iquote"
> "D:/a/qemu/qemu/host/include/x86_64" "-iquote"
> "D:/a/qemu/qemu/host/include/generic" "-iq
> ../net/tap-win32.c: In function 'tap_win32_open':
> ../net/tap-win32.c:343:19: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 176 [-Werror=format-truncation=]
>   343 |              "%s\\%s\\Connection",
>       |                   ^~
>   344 |              NETWORK_CONNECTIONS_KEY, enum_name);
>       |                                       ~~~~~~~~~
> In function 'get_device_guid',
>     inlined from 'tap_win32_open' at ../net/tap-win32.c:616:10:
> ../net/tap-win32.c:341:9: note: 'snprintf' output between 92 and 347
> bytes into a destination of size 256

Is the compiler min/max maxing what UCS-16 or UTF-8 might pack into that string?
>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>  net/tap-win32.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 7edbd716337..4a4625af2b2 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -214,7 +214,7 @@ static int is_tap_win32_dev(const char *guid)
>  
>      for (;;) {
>          char enum_name[256];
> -        char unit_string[256];
> +        char unit_string[512];

If this isn't perf sensitive code lets just get rid of this stack
allocation and be done with some autofree'd g_strdup_printfs?

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2024-10-23 19:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-23 18:30 [PATCH] tap-win32: fix format-truncation warning Pierrick Bouvier
2024-10-23 19:50 ` Alex Bennée [this message]
2024-10-23 20:15   ` Pierrick Bouvier
2024-10-23 21:30     ` Richard Henderson
2024-10-23 21:43       ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875xpilhu6.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.