[Openvpn-devel,v1] plugin: detect too long plugin paths on Windows

Message ID 20261027130028.2220-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] plugin: detect too long plugin paths on Windows |

Commit Message

Gert Doering Oct. 27, 2026, 1 p.m. UTC
  From: Heiko Hund <heiko@ist.eigentlich.net>

GetFullPathNameW() returns the required buffer size if the normalized
path doesn't fit. This case is currently not checked, so a normalized
path longer than MAX_PATH left the buffer empty and the plugin was
then rejected with the misleading message that it is not located in
a trusted directory.

Treat a return value that does not fit into the buffer as failure, so
that the error says that the path could not be normalized. Since
GetFullPathNameW() sets no error code, set ERROR_FILENAME_EXCED_RANGE
manually before logging.

Change-Id: Ib40b439ad84a08fe6d5d4407da18ed78151327e7
Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2039
---

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/+/2039
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/openvpn/plugin.c b/src/openvpn/plugin.c
index a94f07b..9826510 100644
--- a/src/openvpn/plugin.c
+++ b/src/openvpn/plugin.c
@@ -284,8 +284,14 @@ 
     WCHAR *wpath = wide_string(p->so_pathname, &gc);
     WCHAR normalized_plugin_path[MAX_PATH] = { 0 };
     /* Normalize the plugin path, converting any relative paths to absolute paths. */
-    if (!GetFullPathNameW(wpath, MAX_PATH, normalized_plugin_path, NULL))
+    DWORD len = GetFullPathNameW(wpath, _countof(normalized_plugin_path), normalized_plugin_path, NULL);
+    if (len == 0 || len >= _countof(normalized_plugin_path))
     {
+        /* GetFullPathNameW() sets no error code if the buffer is too small */
+        if (len != 0)
+        {
+            SetLastError(ERROR_FILENAME_EXCED_RANGE);
+        }
         msg(M_ERR, "PLUGIN_INIT: could not load plugin DLL: %ls. Failed to normalize plugin path.",
             wpath);
     }