Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2188?usp=email

to review the following change.


Change subject: openvpnserv: check for a leading non-option in the startup data
......................................................................

openvpnserv: check for a leading non-option in the startup data

Check sud.options directly before doing any other work, instead of
building the openvpn.exe command line and parsing it back. This also
rejects empty options.

Change-Id: I14ad4e4511bd9933b89f48ae5a3ac6d2a5e0f2d8
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpnserv/interactive.c
M tests/unit_tests/openvpnserv/test_openvpnserv.c
2 files changed, 10 insertions(+), 46 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/2188/1

diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index f9a2c970..342e4d7 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -354,29 +354,6 @@
     ReturnError(pipe, GetLastError(), func, 1, &exit_event);
 }

-/**
- * Check whether the user options start with a non-option
- *
- * openvpn.exe takes a lone argument as the config file only when there are
- * no other arguments, and takes non-options after the --msg-channel handle
- * as its extra parameters.
- *
- * @param  cmdline  openvpn.exe command line built by the service
- *
- * @return BOOL to indicate if the first user argument is not an option
- */
-static BOOL
-StartsWithNonOption(const WCHAR *cmdline)
-{
-    int argc;
-    WCHAR **argv = CommandLineToArgvW(cmdline, &argc);
-    /* "openvpn --msg-channel <handle> <arg>..." */
-    BOOL ret = argv && argc > 3 && !IsOption(argv[3]);
-
-    LocalFree(argv);
-    return ret;
-}
-
 /*
  * Validate options against a white list. Also check the config_file is
  * inside the config_dir. The white list is defined in validate.c
@@ -3614,6 +3591,16 @@
         goto out;
     }

+    /* openvpn.exe takes non-options after the --msg-channel handle the
+     * service prepends as its extra parameters, not as the config file */
+    if (!IsOption(sud.options + wcsspn(sud.options, L" \t")))
+    {
+        ReturnError(pipe, ERROR_STARTUP_DATA,
+                    L"Options must start with an option, pass the config file 
with --config", 1,
+                    &exit_event);
+        goto out;
+    }
+
     if (!InitializeSecurityDescriptor(&ovpn_sd, SECURITY_DESCRIPTOR_REVISION))
     {
         ReturnLastError(pipe, L"InitializeSecurityDescriptor");
@@ -3858,14 +3845,6 @@
     swprintf(cmdline, cmdline_size, L"openvpn --msg-channel %" PRIuPTR L" %ls",
              (uintptr_t)svc_pipe, sud.options);

-    if (StartsWithNonOption(cmdline))
-    {
-        ReturnError(pipe, ERROR_STARTUP_DATA,
-                    L"Options must start with an option, pass the config file 
with --config", 1,
-                    &exit_event);
-        goto out;
-    }
-
     /*
      * Only authorized users are allowed to use any command line options or
      * have the config file in locations other than the global config 
directory.
diff --git a/tests/unit_tests/openvpnserv/test_openvpnserv.c 
b/tests/unit_tests/openvpnserv/test_openvpnserv.c
index 7db61f7..6ad285f 100644
--- a/tests/unit_tests/openvpnserv/test_openvpnserv.c
+++ b/tests/unit_tests/openvpnserv/test_openvpnserv.c
@@ -302,20 +302,6 @@
 }

 static void
-test_starts_with_non_option(void **state)
-{
-    assert_true(StartsWithNonOption(L"openvpn --msg-channel 1 foo.ovpn"));
-    assert_true(StartsWithNonOption(L"openvpn --msg-channel 1 \"my 
vpn.ovpn\""));
-    assert_true(StartsWithNonOption(L"openvpn --msg-channel 1 foo.ovpn --verb 
3"));
-    assert_true(StartsWithNonOption(L"openvpn --msg-channel 1 foo.ovpn bar"));
-    assert_true(StartsWithNonOption(L"openvpn --msg-channel 1 \"\""));
-
-    assert_false(StartsWithNonOption(L"openvpn --msg-channel 1 "));
-    assert_false(StartsWithNonOption(L"openvpn --msg-channel 1 
--persist-tun"));
-    assert_false(StartsWithNonOption(L"openvpn --msg-channel 1 --config 
foo.ovpn"));
-}
-
-static void
 test_validate_lone_option(void **state)
 {
     WCHAR errmsg[512];
@@ -338,7 +324,6 @@
         cmocka_unit_test(test_append_search_list),
         cmocka_unit_test(test_remove_search_list_tokens),
         cmocka_unit_test(test_merge_openvpn_environment),
-        cmocka_unit_test(test_starts_with_non_option),
         cmocka_unit_test(test_validate_lone_option),
     };


--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2188?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I14ad4e4511bd9933b89f48ae5a3ac6d2a5e0f2d8
Gerrit-Change-Number: 2188
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to