From: Heiko Hund <[email protected]>

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 <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
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 <[email protected]>

        
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);
     }


_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to