net/tap-win32: Fix gcc 14 format truncation errors
PATCH v2 1/1 net/tap-win32: Fix gcc 14 format truncation errors
The patch fixes the following errors generated by GCC 14.2:
../src/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);
| ~~~~~~~~~../src/net/tap-win32.c:341:9: note: 'snprintf' output between 92 and 347 bytes into a destination of size 256
341 | snprintf(connection_string,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
342 | sizeof(connection_string),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
343 | "%s\\%s\\Connection",
| ~~~~~~~~~~~~~~~~~~~~~
344 | NETWORK_CONNECTIONS_KEY, enum_name);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../src/net/tap-win32.c:242:58: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]
242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s",
| ^~
243 | ADAPTER_KEY, enum_name);
| ~~~~~~~~~../src/net/tap-win32.c:242:9: note: 'snprintf' output between 79 and 334 bytes into a destination of size 256
242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243 | ADAPTER_KEY, enum_name);
| ~~~~~~~~~~~~~~~~~~~~~~~../src/net/tap-win32.c:620:52: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 245 [-Werror=format-truncation=]
620 | snprintf (device_path, sizeof(device_path), "%s%s%s",
| ^~
621 | USERMODEDEVICEDIR,
622 | device_guid,
| ~~~~~~~~~~~
../src/net/tap-win32.c:620:5: note: 'snprintf' output between 16 and 271 bytes into a destination of size 256
620 | snprintf (device_path, sizeof(device_path), "%s%s%s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
621 | USERMODEDEVICEDIR,
| ~~~~~~~~~~~~~~~~~~
622 | device_guid,
| ~~~~~~~~~~~~
623 | TAPSUFFIX);
| ~~~~~~~~~~Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2607
Cc: [email protected]
--
This patch was just compile-tested (which fixes my issue). Testing TAP networking under Windows apparently requires extra drivers which I don't want to install (not my computer). So it would be nice if someone could give this patch a test ride. Thanks!
Changes since v1:
* Use g_autofree and g_strdup_printf() rather than fixed size arrays (Peter)
--- net/tap-win32.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
net/tap-win32.c +6 -9
@@ -214,7 +214,7 @@ static int is_tap_win32_dev(const char *guid)for (;;) {char enum_name[256 ]; -char unit_string[256 ]; + g_autofree char *unit_string = NULL;HKEY unit_key;char component_id_string[] ="ComponentId" ;char component_id[256 ];
@@ -239,8 +239,7 @@ static int is_tap_win32_dev(const char *guid)return FALSE; } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" , -ADAPTER_KEY , enum_name); + unit_string =g_strdup_printf ("%s\\%s" ,ADAPTER_KEY , enum_name); status = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
@@ -315,7 +314,7 @@ static int get_device_guid(while (!stop) {char enum_name[256 ]; -char connection_string[256 ]; + g_autofree char *connection_string = NULL;HKEY connection_key;char name_data[256 ];DWORD name_type;
@@ -338,9 +337,7 @@ static int get_device_guid(return -1 ; } -snprintf (connection_string, -sizeof (connection_string), -"%s\\%s\\Connection" , + connection_string =g_strdup_printf ("%s\\%s\\Connection" ,NETWORK_CONNECTIONS_KEY , enum_name); status = RegOpenKeyEx(
@@ -595,7 +592,7 @@ static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,static int tap_win32_open (tap_win32_overlapped_t **phandle,const char *preferred_name) { -char device_path[256 ]; + g_autofree char *device_path = NULL;char device_guid[0x100 ];int rc;HANDLE handle;
@@ -617,7 +614,7 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,if (rc)return -1 ; -snprintf (device_path,sizeof (device_path),"%s%s%s" , + device_path =g_strdup_printf ("%s%s%s" ,USERMODEDEVICEDIR , device_guid,TAPSUFFIX );
Signature · 1 line
2.47.0
Quoted 46 lines · Bernhard Beschow
The patch fixes the following errors generated by GCC 14.2:
../src/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); | ~~~~~~~~~
../src/net/tap-win32.c:341:9: note: 'snprintf' output between 92 and 347 bytes into a destination of size 256341 | snprintf(connection_string, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | sizeof(connection_string), | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 343 | "%s\\%s\\Connection", | ~~~~~~~~~~~~~~~~~~~~~ 344 | NETWORK_CONNECTIONS_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:242:58: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~
../src/net/tap-win32.c:242:9: note: 'snprintf' output between 79 and 334 bytes into a destination of size 256242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:620:52: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 245 [-Werror=format-truncation=]620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~ 621 | USERMODEDEVICEDIR, 622 | device_guid, | ~~~~~~~~~~~ ../src/net/tap-win32.c:620:5: note: 'snprintf' output between 16 and 271 bytes into a destination of size 256 620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 621 | USERMODEDEVICEDIR, | ~~~~~~~~~~~~~~~~~~ 622 | device_guid, | ~~~~~~~~~~~~ 623 | TAPSUFFIX); | ~~~~~~~~~~
Quoted 5 lines
Signed-off-by Bernhard Beschow <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2607
Cc: [email protected]--
---
Quoted 11 lines
This patch was just compile-tested (which fixes my issue). Testing TAP networking under Windows apparently requires extra drivers which I don't want to install (not my computer). So it would be nice if someone could give this patch a test ride. Thanks!
Changes since v1:
* Useg_autofreeandg_strdup_printf()rather than fixed size arrays (Peter)--- net/tap-win32.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
Quoted 6 lines · Bernhard Beschow
The patch fixes the following errors generated by GCC 14.2:
../src/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);
...
Quoted 3 lines
Signed-off-by Bernhard Beschow <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2607
Cc: [email protected]
/mjt
Am 8. Oktober 2024 20:28:42 UTC schrieb Bernhard Beschow <[email protected]>:
Quoted 50 lines
The patch fixes the following errors generated by GCC 14.2:
../src/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); | ~~~~~~~~~
../src/net/tap-win32.c:341:9: note: 'snprintf' output between 92 and 347 bytes into a destination of size 256341 | snprintf(connection_string, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | sizeof(connection_string), | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 343 | "%s\\%s\\Connection", | ~~~~~~~~~~~~~~~~~~~~~ 344 | NETWORK_CONNECTIONS_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:242:58: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~
../src/net/tap-win32.c:242:9: note: 'snprintf' output between 79 and 334 bytes into a destination of size 256242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:620:52: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 245 [-Werror=format-truncation=]620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~ 621 | USERMODEDEVICEDIR, 622 | device_guid, | ~~~~~~~~~~~ ../src/net/tap-win32.c:620:5: note: 'snprintf' output between 16 and 271 bytes into a destination of size 256 620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 621 | USERMODEDEVICEDIR, | ~~~~~~~~~~~~~~~~~~ 622 | device_guid, | ~~~~~~~~~~~~ 623 | TAPSUFFIX); | ~~~~~~~~~~Signed-off-by Bernhard Beschow <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2607
Cc: [email protected]
Quoted 6 lines
--
This patch was just compile-tested (which fixes my issue). Testing TAP networking under Windows apparently requires extra drivers which I don't want to install (not my computer). So it would be nice if someone could give this patch a test ride. Thanks!
Ping. Patch is reviewed. Any testers or shall we just merge?
Best regards,
Bernhard
Quoted 68 lines
Changes since v1:
* Useg_autofreeandg_strdup_printf()rather than fixed size arrays (Peter)
---net/tap-win32.c| 15 ++++++---------1 file changed, 6 insertions(+), 9 deletions(-)net/tap-win32.c +6
-9@@ -214,7 +214,7 @@ static int is_tap_win32_dev(const char *guid)for (;;) {char enum_name[256 ]; -char unit_string[256 ]; + g_autofree char *unit_string = NULL;HKEY unit_key;char component_id_string[] ="ComponentId" ;char component_id[256 ];@@ -239,8 +239,7 @@ static int is_tap_win32_dev(const char *guid)return FALSE; } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" , -ADAPTER_KEY , enum_name); + unit_string =g_strdup_printf ("%s\\%s" ,ADAPTER_KEY , enum_name); status = RegOpenKeyEx( HKEY_LOCAL_MACHINE,@@ -315,7 +314,7 @@ static int get_device_guid(while (!stop) {char enum_name[256 ]; -char connection_string[256 ]; + g_autofree char *connection_string = NULL;HKEY connection_key;char name_data[256 ];DWORD name_type;@@ -338,9 +337,7 @@ static int get_device_guid(return -1 ; } -snprintf (connection_string, -sizeof (connection_string), -"%s\\%s\\Connection" , + connection_string =g_strdup_printf ("%s\\%s\\Connection" ,NETWORK_CONNECTIONS_KEY , enum_name); status = RegOpenKeyEx(@@ -595,7 +592,7 @@ static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,static int tap_win32_open (tap_win32_overlapped_t **phandle,const char *preferred_name) { -char device_path[256 ]; + g_autofree char *device_path = NULL;char device_guid[0x100 ];int rc;HANDLE handle;@@ -617,7 +614,7 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,if (rc)return -1 ; -snprintf (device_path,sizeof (device_path),"%s%s%s" , + device_path =g_strdup_printf ("%s%s%s" ,USERMODEDEVICEDIR , device_guid,TAPSUFFIX );
Quoted 116 lines · Bernhard Beschow
The patch fixes the following errors generated by GCC 14.2:
../src/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); | ~~~~~~~~~
../src/net/tap-win32.c:341:9: note: 'snprintf' output between 92 and 347 bytes into a destination of size 256341 | snprintf(connection_string, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | sizeof(connection_string), | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 343 | "%s\\%s\\Connection", | ~~~~~~~~~~~~~~~~~~~~~ 344 | NETWORK_CONNECTIONS_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:242:58: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 178 [-Werror=format-truncation=]242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~
../src/net/tap-win32.c:242:9: note: 'snprintf' output between 79 and 334 bytes into a destination of size 256242 | snprintf (unit_string, sizeof(unit_string), "%s\\%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 243 | ADAPTER_KEY, enum_name); | ~~~~~~~~~~~~~~~~~~~~~~~
../src/net/tap-win32.c:620:52: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 245 [-Werror=format-truncation=]620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~ 621 | USERMODEDEVICEDIR, 622 | device_guid, | ~~~~~~~~~~~ ../src/net/tap-win32.c:620:5: note: 'snprintf' output between 16 and 271 bytes into a destination of size 256 620 | snprintf (device_path, sizeof(device_path), "%s%s%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 621 | USERMODEDEVICEDIR, | ~~~~~~~~~~~~~~~~~~ 622 | device_guid, | ~~~~~~~~~~~~ 623 | TAPSUFFIX); | ~~~~~~~~~~Signed-off-by Bernhard Beschow <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2607
Cc: [email protected]--
This patch was just compile-tested (which fixes my issue). Testing TAP networking under Windows apparently requires extra drivers which I don't want to install (not my computer). So it would be nice if someone could give this patch a test ride. Thanks!
Changes since v1:
* Useg_autofreeandg_strdup_printf()rather than fixed size arrays (Peter)--- net/tap-win32.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)net/tap-win32.c +5
-8@@ -214,7 +214,7 @@ static int is_tap_win32_dev(const char *guid)for (;;) {char enum_name[256 ]; -char unit_string[256 ]; + g_autofree char *unit_string = NULL;HKEY unit_key;char component_id_string[] ="ComponentId" ;char component_id[256 ];@@ -239,8 +239,7 @@ static int is_tap_win32_dev(const char *guid)return FALSE; } -snprintf (unit_string,sizeof (unit_string),"%s\\%s" , -ADAPTER_KEY , enum_name); + unit_string =g_strdup_printf ("%s\\%s" ,ADAPTER_KEY , enum_name); status = RegOpenKeyEx( HKEY_LOCAL_MACHINE,@@ -315,7 +314,7 @@ static int get_device_guid(while (!stop) {char enum_name[256 ]; -char connection_string[256 ]; + g_autofree char *connection_string = NULL;HKEY connection_key;char name_data[256 ];DWORD name_type;@@ -338,9 +337,7 @@ static int get_device_guid(return -1 ; } -snprintf (connection_string, -sizeof (connection_string), -"%s\\%s\\Connection" , + connection_string =g_strdup_printf ("%s\\%s\\Connection" ,NETWORK_CONNECTIONS_KEY , enum_name); status = RegOpenKeyEx(@@ -595,7 +592,7 @@ static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,static int tap_win32_open (tap_win32_overlapped_t **phandle,const char *preferred_name) { -char device_path[256 ]; + g_autofree char *device_path = NULL;char device_guid[0x100 ];int rc;HANDLE handle;
net/tap-win32.c static int tap_win32_open(tap_win32_overlapped_t **phandle, · line 620
Quoted 8 lines
net/tap-win32.c +1
-1@@ -617,7 +614,7 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,if (rc)return -1 ; -snprintf (device_path,sizeof (device_path),"%s%s%s" , + device_path =g_strdup_printf ("%s%s%s" ,USERMODEDEVICEDIR , device_guid,TAPSUFFIX );
I ran into this as well and reimplemented something similar, but less good than current patch (which should be favored).[1]
I can't test it neither with TAP networking, but content of patch seems correct to me. Hope we can merge it soon (before 9.2).
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Regards,
Pierrick