Browse code

c-rest-engine: Fixing fd leak due to SSL handshake failure

Change-Id: Ieecc638b075c19305d749eb640d945a051bd4784
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5142
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Sharath George

Kumar Kaushik authored on 2018/05/10 07:46:48
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 Name:          c-rest-engine
2 2
 Summary:       minimal http(s) server library
3 3
 Version:       1.2
4
-Release:       4%{?dist}
4
+Release:       5%{?dist}
5 5
 Group:         Applications/System
6 6
 Vendor:        VMware, Inc.
7 7
 License:       Apache 2.0
... ...
@@ -17,6 +17,7 @@ Patch1:        preprocess-timeout.patch
17 17
 Patch2:        typo_fixes.patch
18 18
 Patch3:        ssl_read_error.patch
19 19
 Patch4:        persistent_connection.patch
20
+Patch5:        fd_leak.patch
20 21
 %define sha1   c-rest-engine=25aa9d1f2680e26114dee18365c510692552f8e4
21 22
 
22 23
 %description
... ...
@@ -40,6 +41,7 @@ development libs and header files for c-rest-engine
40 40
 %patch2 -p1
41 41
 %patch3 -p1
42 42
 %patch4 -p1
43
+%patch5 -p1
43 44
 
44 45
 %build
45 46
 cd build
... ...
@@ -72,6 +74,8 @@ find %{buildroot} -name '*.la' -delete
72 72
 # %doc ChangeLog README COPYING
73 73
 
74 74
 %changelog
75
+*  Wed May 09 2018 Kumar Kaushik <kaushikk@vmware.com> 1.2-5
76
+-  Adding patch for file decriptor leak issue.
75 77
 *  Thu Mar 22 2018 Kumar Kaushik <kaushikk@vmware.com> 1.2-4
76 78
 -  Adding support for persistent connection.
77 79
 *  Mon Mar 05 2018 Kumar Kaushik <kaushikk@vmware.com> 1.2-3
78 80
new file mode 100644
... ...
@@ -0,0 +1,93 @@
0
+From e283f74d29c7946814e8239d88156299849da989 Mon Sep 17 00:00:00 2001
1
+From: Kumar Kaushik <kaushikk@vmware.com>
2
+Date: Wed, 9 May 2018 12:27:33 -0700
3
+Subject: [PATCH] Fixing file descriptor leak in case of SSL_accept failure
4
+
5
+Change-Id: If5632e67da7843d7aa7ac48f1363dc58bbea2acb
6
+---
7
+ transport/posix/socket.c | 43 ++++++++++++++++++++++++-------------------
8
+ 1 file changed, 24 insertions(+), 19 deletions(-)
9
+
10
+diff --git a/transport/posix/socket.c b/transport/posix/socket.c
11
+index f50356d..364ce0e 100644
12
+--- a/transport/posix/socket.c
13
+@@ -1160,8 +1160,6 @@ VmSockPosixCloseSocket(
14
+     }
15
+     BAIL_ON_VMREST_ERROR(dwError);
16
+ 
17
+-    VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Closing socket with fd %d, Socket Type %u ( 2-Io / 5-Timer )", pSocket->fd, pSocket->type);
18
+-
19
+     pTimerSocket = pSocket->pTimerSocket;
20
+ 
21
+     /**** Close the timer socket ****/
22
+@@ -1196,15 +1194,20 @@ VmSockPosixCloseSocket(
23
+     /**** Delete from queue if this is NOT timeout ****/
24
+     if ((pSocket->type == VM_SOCK_TYPE_SERVER) && (!(pSocket->bTimerExpired)))
25
+     {
26
+-         dwError = VmSockPosixDeleteEventFromQueue(
27
+-                       pRESTHandle,
28
+-                       pRESTHandle->pSockContext->pEventQueue,
29
+-                       pSocket
30
+-                       );
31
+-         BAIL_ON_VMREST_ERROR(dwError);
32
++        dwError = VmSockPosixDeleteEventFromQueue(
33
++                      pRESTHandle,
34
++                      pRESTHandle->pSockContext->pEventQueue,
35
++                      pSocket
36
++                      );
37
++        if (dwError == VM_SOCK_POSIX_ERROR_SYS_CALL_FAILED)
38
++        {
39
++            VMREST_LOG_WARNING(pRESTHandle,"Delete of IO socket fd %d from event queue failed, still progressing with conn close", pSocket->fd);
40
++            dwError = REST_ENGINE_SUCCESS;
41
++        }
42
++        BAIL_ON_VMREST_ERROR(dwError);
43
+     }
44
+ 
45
+-    /**** Close IO socket fd ****/
46
++    /**** Cleanup the SSL object associated with connection ****/
47
+     if (pRESTHandle->pSSLInfo->isSecure && pSocket->ssl && (pSocket->type != VM_SOCK_TYPE_TIMER))
48
+     {
49
+         if (pSocket->bSSLHandShakeCompleted)
50
+@@ -1220,29 +1223,31 @@ VmSockPosixCloseSocket(
51
+         pSocket->ssl = NULL;
52
+     }
53
+ 
54
+-    if (pSocket->fd >= 0)
55
++cleanup:
56
++
57
++    /**** Close IO socket fd ****/
58
++    if (pSocket && pSocket->fd >= 0)
59
+     {
60
++        VMREST_LOG_INFO(pRESTHandle,"C-REST-ENGINE: Closing socket with fd %d, Socket Type %u ( 2-Io / 5-Timer )", pSocket->fd, pSocket->type);
61
+         close(pSocket->fd);
62
+         pSocket->fd = -1;
63
+     }
64
+ 
65
+-    VmRESTUnlockMutex(pSocket->pMutex);
66
+-    bLockedIO = FALSE;
67
+-
68
+-cleanup:
69
++    if (bLockedIO)
70
++    {
71
++        VmRESTUnlockMutex(pSocket->pMutex);
72
++        bLockedIO = FALSE;
73
++    }
74
+ 
75
+     return dwError;
76
+ 
77
+ error:
78
++    VMREST_LOG_ERROR(pRESTHandle,"Error while closing socket..dwError = %u", dwError);
79
+ 
80
+     if (bLockedTimer)
81
+     {
82
+         VmRESTUnlockMutex(pTimerSocket->pMutex);
83
+-    }
84
+-
85
+-    if (bLockedIO)
86
+-    {
87
+-        VmRESTUnlockMutex(pSocket->pMutex);
88
++        bLockedTimer = FALSE;
89
+     }
90
+ 
91
+     goto cleanup;