merge revision(s) 20189:

* 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_7@22173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2009-02-09 08:35:46 +00:00
parent 7e7ae14016
commit 06df50e382
3 changed files with 27 additions and 9 deletions

View file

@ -1,3 +1,10 @@
Mon Feb 9 17:35:38 2009 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 Feb 9 13:42:15 2009 NAKAMURA Usaku <usa@ruby-lang.org> Mon Feb 9 13:42:15 2009 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (ifs_open_socket): should retry without proto_buffer * win32/win32.c (ifs_open_socket): should retry without proto_buffer

View file

@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-02-09" #define RUBY_RELEASE_DATE "2009-02-09"
#define RUBY_VERSION_CODE 187 #define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20090209 #define RUBY_RELEASE_CODE 20090209
#define RUBY_PATCHLEVEL 110 #define RUBY_PATCHLEVEL 111
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_MINOR 8

View file

@ -2376,21 +2376,32 @@ int
rb_w32_accept(int s, struct sockaddr *addr, int *addrlen) rb_w32_accept(int s, struct sockaddr *addr, int *addrlen)
{ {
SOCKET r; SOCKET r;
int fd;
if (!NtSocketsInitialized) { if (!NtSocketsInitialized) {
StartSockets(); StartSockets();
} }
RUBY_CRITICAL({ RUBY_CRITICAL({
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); r = accept(TO_SOCKET(s), addr, addrlen);
if (r == INVALID_SOCKET) { if (r != INVALID_SOCKET) {
errno = map_errno(WSAGetLastError()); MTHREAD_ONLY(EnterCriticalSection(&(_pioinfo(fd)->lock)));
s = -1; _set_osfhnd(fd, r);
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
CloseHandle(h);
} }
else { else {
s = rb_w32_open_osfhandle(r, O_RDWR|O_BINARY); errno = map_errno(WSAGetLastError());
close(fd);
fd = -1;
} }
}
else
CloseHandle(h);
}); });
return s; return fd;
} }
#undef bind #undef bind