Skip to content

Commit

Permalink
merge revision(s) 20189:
Browse files Browse the repository at this point in the history
	* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@22173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shyouhei committed Feb 9, 2009
1 parent 409282b commit 1fd0d8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1fd0d8c

Please sign in to comment.