[PATCH] tap-win32: Ignore keys too long

Akihiko Odaki posted 1 patch 2 weeks, 2 days ago
net/tap-win32.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
[PATCH] tap-win32: Ignore keys too long
Posted by Akihiko Odaki 2 weeks, 2 days ago
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>
Re: [PATCH] tap-win32: Ignore keys too long
Posted by Daniel P. Berrangé 2 weeks, 2 days ago
On Thu, Nov 07, 2024 at 06:48:44PM +0900, Akihiko Odaki wrote:
> 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(-)

These problems were already fixed by changing to g_strdup_printf

 commit 75fe36b4e8a994cdf9fd6eb601f49e96b1bc791d
 Author: Bernhard Beschow <shentey@gmail.com>
 Date:   Tue Oct 8 22:28:42 2024 +0200

    net/tap-win32: Fix gcc 14 format truncation errors


> 
> 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>
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|