* fhandler_disk_file.cc (fhandler_disk_file::opendir): Check descriptor
created by cygheap_fdnew constructor. * fhandler_virtual.cc (fhandler_virtual::opendir): Ditto. * fhandler_socket.cc (fhandler_socket::accept): Ditto and move creation of file descriptor behind blocking OS call. * net.cc (cygwin_socket): Ditto. (cygwin_rcmd): Ditto. (cygwin_rresvport): Ditto. (cygwin_rexec): Ditto. (socketpair): Ditto.
This commit is contained in:
		| @@ -1,3 +1,16 @@ | ||||
| 2003-02-20  Corinna Vinschen  <corinna@vinschen.de> | ||||
|  | ||||
| 	* fhandler_disk_file.cc (fhandler_disk_file::opendir): Check descriptor | ||||
| 	created by cygheap_fdnew constructor. | ||||
| 	* fhandler_virtual.cc (fhandler_virtual::opendir): Ditto. | ||||
| 	* fhandler_socket.cc (fhandler_socket::accept): Ditto and move | ||||
| 	creation of file descriptor behind blocking OS call. | ||||
| 	* net.cc (cygwin_socket): Ditto. | ||||
| 	(cygwin_rcmd): Ditto. | ||||
| 	(cygwin_rresvport): Ditto. | ||||
| 	(cygwin_rexec): Ditto. | ||||
| 	(socketpair): Ditto. | ||||
|  | ||||
| 2003-02-20  Corinna Vinschen  <corinna@vinschen.de> | ||||
|  | ||||
| 	* autoload.cc (GetCompressedFileSize): Add. | ||||
|   | ||||
| @@ -619,6 +619,8 @@ fhandler_disk_file::opendir (path_conv& real_name) | ||||
|       strcpy (dir->__d_dirname, real_name.get_win32 ()); | ||||
|       dir->__d_dirent->d_version = __DIRENT_VERSION; | ||||
|       cygheap_fdnew fd; | ||||
|       if (fd >= 0) | ||||
|         { | ||||
| 	  fd = this; | ||||
| 	  fd->set_nohandle (true); | ||||
| 	  dir->__d_dirent->d_fd = fd; | ||||
| @@ -636,6 +638,7 @@ fhandler_disk_file::opendir (path_conv& real_name) | ||||
|  | ||||
| 	  res = dir; | ||||
| 	} | ||||
|     } | ||||
|  | ||||
|   syscall_printf ("%p = opendir (%s)", res, get_name ()); | ||||
|   return res; | ||||
|   | ||||
| @@ -484,7 +484,6 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) | ||||
|   WSAEVENT ev[2] = { WSA_INVALID_EVENT, signal_arrived }; | ||||
|   BOOL secret_check_failed = FALSE; | ||||
|   BOOL in_progress = FALSE; | ||||
|   cygheap_fdnew res_fd; | ||||
|  | ||||
|   /* Allows NULL peer and len parameters. */ | ||||
|   struct sockaddr_in peer_dummy; | ||||
| @@ -593,13 +592,16 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) | ||||
| 	} | ||||
|     } | ||||
|  | ||||
|   if (res_fd < 0) | ||||
|     /* FIXME: what is correct errno? */; | ||||
|   else if ((SOCKET) res == (SOCKET) INVALID_SOCKET) | ||||
|   if ((SOCKET) res == (SOCKET) INVALID_SOCKET) | ||||
|     set_winsock_errno (); | ||||
|   else | ||||
|     { | ||||
|       fhandler_socket* res_fh = fdsock (res_fd, get_name (), res); | ||||
|       cygheap_fdnew res_fd; | ||||
|       fhandler_socket* res_fh = NULL; | ||||
|       if (res_fd >= 0) | ||||
| 	  res_fh = fdsock (res_fd, get_name (), res); | ||||
|       if (res_fh) | ||||
|         { | ||||
| 	  if (get_addr_family () == AF_LOCAL) | ||||
| 	    res_fh->set_sun_path (get_sun_path ()); | ||||
| 	  res_fh->set_addr_family (get_addr_family ()); | ||||
| @@ -607,6 +609,12 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) | ||||
| 	  res_fh->set_connect_state (CONNECTED); | ||||
| 	  res = res_fd; | ||||
| 	} | ||||
|       else | ||||
|         { | ||||
| 	  closesocket (res); | ||||
| 	  res = -1; | ||||
| 	} | ||||
|     } | ||||
|  | ||||
| done: | ||||
|   if (ev[0] != WSA_INVALID_EVENT) | ||||
|   | ||||
| @@ -74,6 +74,8 @@ fhandler_virtual::opendir (path_conv& pc) | ||||
|       strcpy (dir->__d_dirname, get_name ()); | ||||
|       dir->__d_dirent->d_version = __DIRENT_VERSION; | ||||
|       cygheap_fdnew fd; | ||||
|       if (fd >= 0) | ||||
|         { | ||||
| 	  fd = this; | ||||
| 	  fd->set_nohandle (true); | ||||
| 	  dir->__d_dirent->d_fd = fd; | ||||
| @@ -85,6 +87,7 @@ fhandler_virtual::opendir (path_conv& pc) | ||||
|  | ||||
| 	  res = dir; | ||||
| 	} | ||||
|     } | ||||
|  | ||||
|   syscall_printf ("%p = opendir (%s)", res, get_name ()); | ||||
|   return res; | ||||
|   | ||||
| @@ -540,10 +540,6 @@ cygwin_socket (int af, int type, int protocol) | ||||
|   SOCKET soc = 0; | ||||
|   fhandler_socket *fh = NULL; | ||||
|  | ||||
|   cygheap_fdnew fd; | ||||
|  | ||||
|   if (fd >= 0) | ||||
|     { | ||||
|   debug_printf ("socket (%d, %d, %d)", af, type, protocol); | ||||
|  | ||||
|   soc = socket (AF_INET, type, af == AF_LOCAL ? 0 : protocol); | ||||
| @@ -561,18 +557,18 @@ cygwin_socket (int af, int type, int protocol) | ||||
|   else | ||||
|     name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket"); | ||||
|  | ||||
|       fh = fdsock (fd, name, soc); | ||||
|       if (!fh) | ||||
|   { | ||||
| 	  closesocket (soc); | ||||
| 	  res = -1; | ||||
| 	} | ||||
|       else | ||||
|     cygheap_fdnew fd; | ||||
|     if (fd >= 0) | ||||
|       fh = fdsock (fd, name, soc); | ||||
|     if (fh) | ||||
|       { | ||||
| 	fh->set_addr_family (af); | ||||
| 	fh->set_socket_type (type); | ||||
| 	res = fd; | ||||
|       } | ||||
|     else | ||||
| 	closesocket (soc); | ||||
|   } | ||||
|  | ||||
| done: | ||||
| @@ -1901,6 +1897,7 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser, | ||||
| { | ||||
|   int res = -1; | ||||
|   SOCKET fd2s; | ||||
|  | ||||
|   sig_dispatch_pending (0); | ||||
|   sigframe thisframe (mainthread); | ||||
|  | ||||
| @@ -1910,33 +1907,40 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser, | ||||
|       (remuser && check_null_str_errno (remuser))) | ||||
|     return (int) INVALID_SOCKET; | ||||
|  | ||||
|   res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p ? &fd2s : NULL); | ||||
|   if (res != (int) INVALID_SOCKET) | ||||
|     { | ||||
|       fhandler_socket *fh = NULL; | ||||
|       cygheap_fdnew res_fd; | ||||
|  | ||||
|   if (res_fd < 0) | ||||
|     goto done; | ||||
|       if (res_fd >= 0) | ||||
| 	fh = fdsock (res_fd, "/dev/tcp", res); | ||||
|       if (fh) | ||||
| 	res = res_fd; | ||||
|       else | ||||
| 	{ | ||||
| 	  closesocket (res); | ||||
| 	  res = -1; | ||||
| 	} | ||||
|  | ||||
|   if (fd2p) | ||||
|       if (res >= 0 && fd2p) | ||||
| 	{ | ||||
| 	  cygheap_fdnew newfd (res_fd, false); | ||||
|  | ||||
|       if (*fd2p < 0) | ||||
| 	goto done; | ||||
| 	  fh = NULL; | ||||
| 	  if (newfd >= 0) | ||||
| 	    fh = fdsock (*fd2p, "/dev/tcp", fd2s); | ||||
| 	  if (fh) | ||||
| 	    *fd2p = newfd; | ||||
|     } | ||||
|  | ||||
|   res = rcmd (ahost, inport, locuser, remuser, cmd, fd2p ? &fd2s : NULL); | ||||
|   if (res == (int) INVALID_SOCKET) | ||||
|     goto done; | ||||
| 	  else | ||||
| 	    { | ||||
|       fdsock (res_fd, "/dev/tcp", res); | ||||
|       res = res_fd; | ||||
| 	      closesocket (res); | ||||
| 	      closesocket (fd2s); | ||||
| 	      res = -1; | ||||
| 	    } | ||||
| 	} | ||||
|     } | ||||
|  | ||||
|   if (fd2p) | ||||
|     fdsock (*fd2p, "/dev/tcp", fd2s); | ||||
|  | ||||
| done: | ||||
|   syscall_printf ("%d = rcmd (...)", res); | ||||
|   return res; | ||||
| } | ||||
| @@ -1952,19 +1956,19 @@ cygwin_rresvport (int *port) | ||||
|   if (check_null_invalid_struct_errno (port)) | ||||
|     return -1; | ||||
|  | ||||
|   cygheap_fdnew res_fd; | ||||
|  | ||||
|   if (res_fd < 0) | ||||
|     res = -1; | ||||
|   else | ||||
|     { | ||||
|   res = rresvport (port); | ||||
|  | ||||
|   if (res != (int) INVALID_SOCKET) | ||||
|     { | ||||
| 	  fdsock (res_fd, "/dev/tcp", res); | ||||
|       fhandler_socket *fh = NULL; | ||||
|       cygheap_fdnew res_fd; | ||||
|  | ||||
|       if (res_fd >= 0) | ||||
| 	fh = fdsock (res_fd, "/dev/tcp", res); | ||||
|       if (fh) | ||||
|         res = res_fd; | ||||
| 	} | ||||
|       else | ||||
| 	res = -1; | ||||
|     } | ||||
|  | ||||
|   syscall_printf ("%d = rresvport (%d)", res, port ? *port : 0); | ||||
| @@ -1987,30 +1991,40 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser, | ||||
|       (password && check_null_str_errno (password))) | ||||
|     return (int) INVALID_SOCKET; | ||||
|  | ||||
|   res = rexec (ahost, inport, locuser, password, cmd, fd2p ? &fd2s : NULL); | ||||
|   if (res != (int) INVALID_SOCKET) | ||||
|     { | ||||
|       fhandler_socket *fh = NULL; | ||||
|       cygheap_fdnew res_fd; | ||||
|  | ||||
|   if (res_fd < 0) | ||||
|     goto done; | ||||
|   if (fd2p) | ||||
|     { | ||||
|       cygheap_fdnew newfd (res_fd); | ||||
|  | ||||
|       if (newfd < 0) | ||||
| 	goto done; | ||||
|       *fd2p = newfd; | ||||
|     } | ||||
|   res = rexec (ahost, inport, locuser, password, cmd, fd2p ? &fd2s : NULL); | ||||
|   if (res == (int) INVALID_SOCKET) | ||||
|     goto done; | ||||
|       if (res_fd >= 0) | ||||
| 	fh = fdsock (res_fd, "/dev/tcp", res); | ||||
|       if (fh) | ||||
| 	res = res_fd; | ||||
|       else | ||||
| 	{ | ||||
|       fdsock (res_fd, "/dev/tcp", res); | ||||
|       res = res_fd; | ||||
| 	  closesocket (res); | ||||
| 	  res = -1; | ||||
| 	} | ||||
|  | ||||
|       if (res >= 0 && fd2p) | ||||
| 	{ | ||||
| 	  cygheap_fdnew newfd (res_fd, false); | ||||
|  | ||||
| 	  fh = NULL; | ||||
| 	  if (newfd >= 0) | ||||
| 	    fh = fdsock (*fd2p, "/dev/tcp", fd2s); | ||||
| 	  if (fh) | ||||
| 	    *fd2p = newfd; | ||||
| 	  else | ||||
| 	    { | ||||
| 	      closesocket (res); | ||||
| 	      closesocket (fd2s); | ||||
| 	      res = -1; | ||||
| 	    } | ||||
| 	} | ||||
|     } | ||||
|   if (fd2p) | ||||
|     fdsock (*fd2p, "/dev/tcp", fd2s); | ||||
|  | ||||
| done: | ||||
|   syscall_printf ("%d = rexec (...)", res); | ||||
|   return res; | ||||
| } | ||||
| @@ -2024,8 +2038,6 @@ socketpair (int family, int type, int protocol, int *sb) | ||||
|   SOCKET insock, outsock, newsock; | ||||
|   struct sockaddr_in sock_in, sock_out; | ||||
|   int len; | ||||
|   cygheap_fdnew sb0; | ||||
|   fhandler_socket *fh; | ||||
|  | ||||
|   sig_dispatch_pending (0); | ||||
|   sigframe thisframe (mainthread); | ||||
| @@ -2049,19 +2061,6 @@ socketpair (int family, int type, int protocol, int *sb) | ||||
|       goto done; | ||||
|     } | ||||
|  | ||||
|   if (sb0 < 0) | ||||
|     goto done; | ||||
|   else | ||||
|     { | ||||
|       sb[0] = sb0; | ||||
|       cygheap_fdnew sb1 (sb0, false); | ||||
|  | ||||
|       if (sb1 < 0) | ||||
| 	goto done; | ||||
|  | ||||
|       sb[1] = sb1; | ||||
|     } | ||||
|  | ||||
|   /* create the first socket */ | ||||
|   newsock = socket (AF_INET, type, 0); | ||||
|   if (newsock == INVALID_SOCKET) | ||||
| @@ -2175,34 +2174,46 @@ socketpair (int family, int type, int protocol, int *sb) | ||||
|       insock = newsock; | ||||
|     } | ||||
|  | ||||
|   res = 0; | ||||
|  | ||||
|   if (family == AF_LOCAL) | ||||
|   { | ||||
|     fhandler_socket *fh = NULL; | ||||
|     cygheap_fdnew sb0; | ||||
|     const char *name; | ||||
|  | ||||
|       fh = fdsock (sb[0], | ||||
| 		   type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket", | ||||
| 		   insock); | ||||
|       fh->set_sun_path (""); | ||||
|       fh->set_addr_family (AF_LOCAL); | ||||
|       fh->set_socket_type (type); | ||||
|       fh = fdsock (sb[1], | ||||
| 		   type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket", | ||||
| 		   outsock); | ||||
|       fh->set_sun_path (""); | ||||
|       fh->set_addr_family (AF_LOCAL); | ||||
|       fh->set_socket_type (type); | ||||
|     } | ||||
|     if (family == AF_INET) | ||||
|       name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp"); | ||||
|     else | ||||
|       name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket"); | ||||
|  | ||||
|     if (sb0 >= 0) | ||||
|       fh = fdsock (sb0, name, insock); | ||||
|     if (fh) | ||||
|       { | ||||
|       fh = fdsock (sb[0], type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp", | ||||
| 		   insock); | ||||
|       fh->set_addr_family (AF_INET); | ||||
| 	fh->set_sun_path (""); | ||||
| 	fh->set_addr_family (family); | ||||
| 	fh->set_socket_type (type); | ||||
|       fh = fdsock (sb[1], type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp", | ||||
| 		   outsock); | ||||
|       fh->set_addr_family (AF_INET); | ||||
|  | ||||
| 	cygheap_fdnew sb1 (sb0, false); | ||||
|  | ||||
| 	fh = NULL; | ||||
| 	if (sb1 >= 0) | ||||
| 	  fh = fdsock (sb1, name, outsock); | ||||
| 	if (fh) | ||||
| 	  { | ||||
| 	    fh->set_sun_path (""); | ||||
| 	    fh->set_addr_family (family); | ||||
| 	    fh->set_socket_type (type); | ||||
|  | ||||
| 	    sb[0] = sb0; | ||||
| 	    sb[1] = sb1; | ||||
| 	    res = 0; | ||||
| 	  } | ||||
|       } | ||||
|  | ||||
|     if (res == -1) | ||||
|       { | ||||
|         closesocket (insock); | ||||
| 	closesocket (outsock); | ||||
|       } | ||||
|   } | ||||
|  | ||||
| done: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user