summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 08:35:04 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 08:35:04 +0000
commit9755536ac2f6674c6915a559bd72c1c44b6a5672 (patch)
treebe08b58a1690a300dc36a6c164718a78e98bc9bd
parentfc601f0f64701e8e95f69e19e1c8b34515ad7a81 (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_6@22171 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 c1301f9d4f..355edcaff1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Feb 9 17:34:55 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:41:50 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 dfdf270e40..d4d004ce8f 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-02-09"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20090209
-#define RUBY_PATCHLEVEL 324
+#define RUBY_PATCHLEVEL 325
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
diff --git a/win32/win32.c b/win32/win32.c
index 4b83480ff1..3b49ecaa85 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2196,21 +2196,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