cvs: php4 /sapi/cgi/libfcgi os_win32.c
| From: | Shane Caraveo | Date: | Sun, 17 Mar 2002 08:21:18 +0000 |
| Subject: | cvs: php4 /sapi/cgi/libfcgi os_win32.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-10282@lists.php.net to get a copy of this message | ||
shane Sun Mar 17 03:21:18 2002 EDT
Modified files:
/php4/sapi/cgi/libfcgi os_win32.c
Log:
fix closing pipes
fix buffer overrun
Index: php4/sapi/cgi/libfcgi/os_win32.c
diff -u php4/sapi/cgi/libfcgi/os_win32.c:1.2 php4/sapi/cgi/libfcgi/os_win32.c:1.3
--- php4/sapi/cgi/libfcgi/os_win32.c:1.2 Mon Mar 11 02:58:52 2002
+++ php4/sapi/cgi/libfcgi/os_win32.c Sun Mar 17 03:21:18 2002
@@ -17,7 +17,7 @@
* significantly more enjoyable.)
*/
#ifndef lint
-static const char rcsid[] = "$Id: os_win32.c,v 1.2 2002/03/11 07:58:52 sebastian Exp $";
+static const char rcsid[] = "$Id: os_win32.c,v 1.3 2002/03/17 08:21:18 shane Exp $";
#endif /* not lint */
#define WIN32_LEAN_AND_MEAN
@@ -631,7 +631,6 @@
fdTable[fd].path = NULL;
break;
case FD_PIPE_ASYNC:
- CloseHandle((HANDLE)fdTable[fd].fid.value);
break;
default:
break;
@@ -854,11 +853,17 @@
if (*bindPath != ':')
{
char * p = strchr(bindPath, ':');
- int len = p - bindPath + 1;
+ if (p) {
+ int len = p - bindPath + 1;
- host = malloc(len);
- strncpy(host, bindPath, len);
- host[len] = '\0';
+ host = malloc(len);
+ if (!host) {
+ fprintf(stderr, "Unable to allocate memory\n");
+ return -1;
+ }
+ strncpy(host, bindPath, len);
+ host[len-1] = '\0';
+ }
}
hp = gethostbyname(host ? host : LOCALHOST);
@@ -885,7 +890,7 @@
return -1;
}
- if (! connect(sock, (struct sockaddr *) &sockAddr, sockLen))
+ if (connect(sock, (struct sockaddr *) &sockAddr, sockLen) == SOCKET_ERROR)
{
closesocket(sock);
return -1;
@@ -988,6 +993,7 @@
else
{
fdTable[fd].Errno = GetLastError();
+ ret = -1;
}
break;
@@ -1403,21 +1409,38 @@
case FD_PIPE_ASYNC:
case FD_FILE_SYNC:
case FD_FILE_ASYNC:
- break;
-
- case FD_SOCKET_SYNC:
+ /*
+ * CloseHandle returns: TRUE success, 0 failure
+ */
+ if (CloseHandle(fdTable[fd].fid.fileHandle) == FALSE)
+ ret = -1;
+ break;
+ case FD_SOCKET_SYNC:
case FD_SOCKET_ASYNC:
/*
* Closing a socket that has an async read outstanding causes a
* tcp reset and possible data loss. The shutdown call seems to
* prevent this.
*/
- shutdown(fdTable[fd].fid.sock, 2);
- /*
+
+ /* shutdown(fdTable[fd].fid.sock, SD_BOTH); */
+
+ {
+ char buf[16];
+ int r;
+
+ shutdown(fdTable[fd].fid.sock,SD_SEND);
+
+ do
+ {
+ r = recv(fdTable[fd].fid.sock,buf,16,0);
+ } while (r > 0);
+ }
+ /*
* closesocket returns: 0 success, SOCKET_ERROR failure
*/
if (closesocket(fdTable[fd].fid.sock) == SOCKET_ERROR)
- ret = -1;
+ ret = -1;
break;
default:
return -1; /* fake failure */
@@ -1452,7 +1475,7 @@
ASSERT(fdTable[fd].type == FD_SOCKET_ASYNC
|| fdTable[fd].type == FD_SOCKET_SYNC);
- if (shutdown(fdTable[fd].fid.sock,0) == SOCKET_ERROR)
+ if (shutdown(fdTable[fd].fid.sock,SD_RECEIVE) == SOCKET_ERROR)
ret = -1;
return ret;
}
@@ -1894,7 +1917,7 @@
if (fdTable[fd].type == FD_SOCKET_SYNC && flags == O_NONBLOCK) {
if (ioctlsocket(fdTable[fd].fid.sock, FIONBIO, &pLong) ==
- SOCKET_ERROR) {
+ SOCKET_ERROR) {
//exit(WSAGetLastError());
SetLastError(WSAGetLastError());
return;