[Openvpn-devel,v1] tapctl: don't crash on a missing list --hwid value

Message ID 20261130152742.17661-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] tapctl: don't crash on a missing list --hwid value |

Commit Message

Gert Doering Nov. 30, 2026, 3:27 p.m. UTC
  From: Razvan Cojocaru <razvanc@mailbox.org>

"tapctl list --hwid" without a value crashed in wcslen(), and a value
too long for the hardware ID buffer made memcpy_s() fail.

Warn and ignore --hwid in both cases, as the create command does.

Change-Id: I21c051e6fa7b89904da2d4d6ec4770c94bc44af7
Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2376
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2376
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Patch

diff --git a/src/tapctl/main.c b/src/tapctl/main.c
index 6697d14..12ab270 100644
--- a/src/tapctl/main.c
+++ b/src/tapctl/main.c
@@ -512,11 +512,20 @@ 
     {
         if (wcsicmp(argv[i], L"--hwid") == 0)
         {
+            if (++i >= argc)
+            {
+                fwprintf(stderr, L"--hwid option requires a value. Ignored.\n");
+                break;
+            }
+            /* leave room for the two terminating zeros */
+            size_t len = wcslen(argv[i]);
+            if (len > _countof(szzHwId) - 2)
+            {
+                fwprintf(stderr, L"--hwid value is too long. Ignored.\n");
+                continue;
+            }
             memset(szzHwId, 0, sizeof(szzHwId));
-            ++i;
-            memcpy_s(szzHwId,
-                     sizeof(szzHwId) - 2 * sizeof(WCHAR),
-                     argv[i], wcslen(argv[i]) * sizeof(WCHAR));
+            wmemcpy(szzHwId, argv[i], len);
         }
         else
         {