Skip to content

Commit 0c9e68a

Browse files
committed
rfb/rfbproto: extend rfbCloseSocket() to prevent double closes
Specifically on Android newer 11, this would cause aborts by the fdsan checker, see https://developer.android.com/about/versions/11/behavior-changes-all#fdsan It's also generally safer to mark a closed fd as closed as to not try to re-use it.
1 parent 593c1c3 commit 0c9e68a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

rfb/rfbproto.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef int8_t rfbBool;
9393
#ifdef WIN32
9494
#define rfbSocket SOCKET
9595
#define RFB_INVALID_SOCKET INVALID_SOCKET
96-
#define rfbCloseSocket closesocket
96+
#define _rfbCloseSocket closesocket
9797
#else
9898
#ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
9999
#include <sys/time.h>
@@ -104,13 +104,20 @@ typedef int8_t rfbBool;
104104
#define rfbSocket int
105105
#define SOCKET int /* LibVNCServer versions older than 0.9.13 defined this for non-Windows, so keep it here */
106106
#define RFB_INVALID_SOCKET (-1)
107-
#define rfbCloseSocket close
107+
#define _rfbCloseSocket close
108108
typedef int8_t rfbBool;
109109
#undef FALSE
110110
#define FALSE 0
111111
#undef TRUE
112112
#define TRUE -1
113113
#endif
114+
#define rfbCloseSocket(s) \
115+
{ \
116+
if (s != RFB_INVALID_SOCKET) { \
117+
_rfbCloseSocket(s); \
118+
s = RFB_INVALID_SOCKET; \
119+
} \
120+
}
114121

115122
typedef uint32_t rfbKeySym;
116123
typedef uint32_t rfbPixel;

0 commit comments

Comments
 (0)