Skip to content

Commit f1a5f5e

Browse files
palichoroba
authored andcommitted
On Windows do not take WINAPI HANDLE of non-socket connections
MariaDB and MySQL client libraries on Windows return zero value in my_socket type when connection to server is not of socket type. Zero value may be interpreted as file descriptor for stdin, so skip processing of the zero value in socket related functions.
1 parent 78f031b commit f1a5f5e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

dbdimp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,10 @@ static int mariadb_dr_socket_cloexec(my_socket sock_os)
14011401
DWORD flags;
14021402
int error;
14031403

1404+
/* Ignore connections without valid socket handle */
1405+
if (sock_os == 0)
1406+
return 0;
1407+
14041408
if (!GetHandleInformation(handle, &flags))
14051409
{
14061410
error = GetLastError();
@@ -2413,17 +2417,19 @@ static bool mariadb_dr_connect(
24132417
/*
24142418
Client library returns socket in my_socket type, which is C file
24152419
descriptor on Linux or Windows native socket type on Windows.
2420+
On Windows it can be zero in case connection type is not socket.
24162421
Perl requires sockets to always be in C file descriptor type,
24172422
so on Windows associate it with C file descriptor via Perl's
24182423
win32_open_osfhandle() function.
24192424
*/
24202425
#ifdef _WIN32
2421-
imp_dbh->sock_fd = win32_open_osfhandle(sock_os, O_RDWR|O_BINARY);
2426+
imp_dbh->sock_fd = sock_os != 0 ? win32_open_osfhandle(sock_os, O_RDWR|O_BINARY) : -1;
24222427
#else
24232428
imp_dbh->sock_fd = sock_os;
24242429
#endif
24252430

24262431
#ifdef _WIN32
2432+
if (imp_dbh->sock_fd >= 0)
24272433
{
24282434
/*
24292435
* Winsock SO_UPDATE_CONNECT_CONTEXT option needs to be set on the socket,

0 commit comments

Comments
 (0)