Skip to contentSkip to conversation

Fix possible access of uninitialized pipe handles

PATCH In review [email protected]... 2 participants 3 messages Feb 20, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix possible access of uninitialized pipe handles

From: Selva Nair <[email protected]...>

Compile time warning for openvpnserv.exe
interactive.c: In function ‘RunOpenvpn’:
interactive.c:160:27: warning: ‘svc_pipe’ may be used uninitialized in this function [-Wmaybe-uninitialized]

When RunOpenvpn exits early due to errors, uninitialized svc_pipe and ovpn_pipe vars could get passed to CloseHandleEx(). Fix by initializing to NULL.

---
 src/openvpnserv/interactive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpnserv/interactive.c +1 -1
index 710f9c7..8da49be 100644
@@ -1468,7 +1468,7 @@ static DWORD WINAPI
 RunOpenvpn(LPVOID p)
 {
     HANDLE pipe = p;
-    HANDLE ovpn_pipe, svc_pipe;
+    HANDLE ovpn_pipe = NULL, svc_pipe = NULL;
     PTOKEN_USER svc_user = NULL, ovpn_user = NULL;
     HANDLE svc_token = NULL, imp_token = NULL, pri_token = NULL;
     HANDLE stdin_read = NULL, stdin_write = NULL;
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw

Strangely, I do not see this warning (unlike another one about error in common.c)
with GCC 7.3 despite adding -O1 and -Wmaybe-uninitialized.

Change looks reasonable, compiled with MSVC and MinGW.

author
#2 lore raw

Hi

Quoted 4 lines · Lev Stipakov

Strangely, I do not see this warning (unlike another one about error in common.c)
with GCC 7.3 despite adding -O1 and -Wmaybe-uninitialized.

I saw it on the travis build. With gcc 7.3, for some reason, -O1 doesn't show it but -O2 or higher does. Some older versions of gcc seem to show it only with require -O3 or higher!

But the potential for attempting to close wrong handles looks real.

Thanks,

Selva