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/+/2356?usp=email

to review the following change.


Change subject: openvpnserv: report pipe creation errors where they happen
......................................................................

openvpnserv: report pipe creation errors where they happen

Log failures to create or disconnect the first pipe instance with
their own messages, instead of falling through to the generic one.
This makes a pipe name already in use distinguishable, and logs
the error before CloseHandleEx() can clobber it.

Change-Id: Id795de7dfe1324fb00660b6f8a9043732aa3e84c
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpnserv/interactive.c
1 file changed, 13 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/56/2356/1

diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index 1cb191a..a381fa1 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -4066,35 +4066,34 @@
     swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) 
L"%ls\\service",
              service_instance);

+    HANDLE pipe = INVALID_HANDLE_VALUE;
+
     static HANDLE blocker = INVALID_HANDLE_VALUE;
     if (blocker == INVALID_HANDLE_VALUE)
     {
         blocker = CreateNamedPipe(pipe_name, flags | 
FILE_FLAG_FIRST_PIPE_INSTANCE, mode,
                                   PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, 
&sa);
-        if (blocker != INVALID_HANDLE_VALUE && !DisconnectNamedPipe(blocker))
+        if (blocker == INVALID_HANDLE_VALUE)
         {
-            DWORD error = GetLastError();
+            MsgToEventLog(M_SYSERR, L"Could not create first instance of named 
pipe");
+            goto out;
+        }
+        if (!DisconnectNamedPipe(blocker))
+        {
+            MsgToEventLog(M_SYSERR, L"Could not disconnect first instance of 
named pipe");
             CloseHandleEx(&blocker);
-            SetLastError(error);
+            goto out;
         }
     }

-    /* Without the first instance, fail and try again with the next call */
-    HANDLE pipe = INVALID_HANDLE_VALUE;
-    if (blocker != INVALID_HANDLE_VALUE)
-    {
-        pipe = CreateNamedPipe(pipe_name, flags, mode, 
PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0,
-                               &sa);
-    }
-
-    LocalFree(sd);
-
+    pipe = CreateNamedPipe(pipe_name, flags, mode, PIPE_UNLIMITED_INSTANCES, 
1024, 1024, 0, &sa);
     if (pipe == INVALID_HANDLE_VALUE)
     {
         MsgToEventLog(M_SYSERR, L"Could not create named pipe");
-        return INVALID_HANDLE_VALUE;
     }

+out:
+    LocalFree(sd);
     return pipe;
 }


-- 
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2356?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: Id795de7dfe1324fb00660b6f8a9043732aa3e84c
Gerrit-Change-Number: 2356
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