1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* win32/win32.c (rb_w32_accept): secure fd before accept because if

error causes in securing, cannot restore the state of accepted
	  socket.
	  fixed [ruby-core:19728]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2008-11-11 08:54:07 +00:00
parent 54b2fa7e3d
commit 9729b68721
2 changed files with 26 additions and 8 deletions

View file

@ -1,3 +1,10 @@
Tue Nov 11 17:51:30 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_accept): secure fd before accept because if
error causes in securing, cannot restore the state of accepted
socket.
fixed [ruby-core:19728]
Mon Nov 10 18:06:51 2008 Akinori MUSHA <knu@iDaemons.org>
* ext/dbm/dbm.c (fdbm_key): Rename #index to #key. Emit a warning

View file

@ -2379,21 +2379,32 @@ int
rb_w32_accept(int s, struct sockaddr *addr, int *addrlen)
{
SOCKET r;
int fd;
if (!NtSocketsInitialized) {
StartSockets();
}
RUBY_CRITICAL({
r = accept(TO_SOCKET(s), addr, addrlen);
if (r == INVALID_SOCKET) {
errno = map_errno(WSAGetLastError());
s = -1;
}
else {
s = rb_w32_open_osfhandle(r, O_RDWR|O_BINARY);
HANDLE h = CreateFile("NUL", 0, 0, NULL, OPEN_ALWAYS, 0, NULL);
fd = rb_w32_open_osfhandle((long)h, O_RDWR|O_BINARY|O_NOINHERIT);
if (fd != -1) {
r = accept(TO_SOCKET(s), addr, addrlen);
if (r != INVALID_SOCKET) {
MTHREAD_ONLY(EnterCriticalSection(&(_pioinfo(fd)->lock)));
_set_osfhnd(fd, r);
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
CloseHandle(h);
}
else {
errno = map_errno(WSAGetLastError());
close(fd);
fd = -1;
}
}
else
CloseHandle(h);
});
return s;
return fd;
}
#undef bind