summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 08:35:46 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 08:35:46 +0000
commit06df50e38288d1720f31016170377cbe0989438c (patch)
tree0f8af3d1366aca1d719acc34c23f63782e9eb1fd
parent7e7ae14016dcc7df0f2fb3d5f2d2f9f7fcc31397 (diff)
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
-rw-r--r--ChangeLog7
-rw-r--r--version.h2
-rw-r--r--win32/win32.c27
3 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 706488493b..fe31aad7c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* win32/win32.c (ifs_open_socket): should retry without proto_buffer
diff --git a/version.h b/version.h
index bad27eca14..2d61e439ef 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-02-09"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20090209
-#define RUBY_PATCHLEVEL 110
+#define RUBY_PATCHLEVEL 111
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
diff --git a/win32/win32.c b/win32/win32.c
index 8fb1d2d860..44de047716 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2376,21 +2376,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