qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: Jason Wang <jasowang@redhat.com>, Stefan Weil <sw@weilnetz.de>
Cc: qemu-devel@nongnu.org, devel@daynix.com,
	 Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH] tap-win32: Ignore keys too long
Date: Thu, 07 Nov 2024 18:48:44 +0900	[thread overview]
Message-ID: <20241107-win32-v1-1-952d508e2546@daynix.com> (raw)

Registry keys get truncated and trigger -Wformat-truncation. Ignore
such truncated keys as they are invalid.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 net/tap-win32.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/net/tap-win32.c b/net/tap-win32.c
index 7edbd7163370..4081ba87991f 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -239,8 +239,12 @@ static int is_tap_win32_dev(const char *guid)
             return FALSE;
         }
 
-        snprintf (unit_string, sizeof(unit_string), "%s\\%s",
-                  ADAPTER_KEY, enum_name);
+        len = snprintf(unit_string, sizeof(unit_string), "%s\\%s",
+                       ADAPTER_KEY, enum_name);
+        if (len >= sizeof(unit_string)) {
+            ++i;
+            continue;
+        }
 
         status = RegOpenKeyEx(
             HKEY_LOCAL_MACHINE,
@@ -338,10 +342,13 @@ static int get_device_guid(
             return -1;
         }
 
-        snprintf(connection_string,
-             sizeof(connection_string),
-             "%s\\%s\\Connection",
-             NETWORK_CONNECTIONS_KEY, enum_name);
+        len = snprintf(connection_string, sizeof(connection_string),
+                       "%s\\%s\\Connection",
+                       NETWORK_CONNECTIONS_KEY, enum_name);
+        if (len >= sizeof(connection_string)) {
+            ++i;
+            continue;
+        }
 
         status = RegOpenKeyEx(
             HKEY_LOCAL_MACHINE,
@@ -617,10 +624,11 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
     if (rc)
         return -1;
 
-    snprintf (device_path, sizeof(device_path), "%s%s%s",
-              USERMODEDEVICEDIR,
-              device_guid,
-              TAPSUFFIX);
+    rc = snprintf(device_path, sizeof(device_path), "%s%s%s",
+                  USERMODEDEVICEDIR, device_guid, TAPSUFFIX);
+    if (rc >= sizeof(device_path)) {
+        return -1;
+    }
 
     handle = CreateFile (
         device_path,

---
base-commit: 7e3b6d8063f245d27eecce5aabe624b5785f2a77
change-id: 20241107-win32-b8f0d15c9122

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>



             reply	other threads:[~2024-11-07  9:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  9:48 Akihiko Odaki [this message]
2024-11-07  9:52 ` [PATCH] tap-win32: Ignore keys too long Daniel P. Berrangé

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=20241107-win32-v1-1-952d508e2546@daynix.com \
    --to=akihiko.odaki@daynix.com \
    --cc=devel@daynix.com \
    --cc=jasowang@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).