OSDN Git Service

Fix heap corruption in nio select(2) code.
authorElliott Hughes <enh@google.com>
Fri, 18 Sep 2009 01:32:07 +0000 (18:32 -0700)
committerElliott Hughes <enh@google.com>
Fri, 18 Sep 2009 18:52:23 +0000 (11:52 -0700)
commitcda2fae64ff87cc515263e343f332988c61a6476
treecf69a42e9ad934efc397ce9f76f8ada09fb17f92
parent549d1a84acaaeef2ae6f34e9c4857c37b8e2e4fd
Fix heap corruption in nio select(2) code.

The active ingredient in this change is that we now test that the fd isn't -1,
used to represent an invalid fd. There's a race condition where a socket can be
closed between SelectorImpl.prepareChannels and the native code. This caused us
to write to the -1th element of a heap-allocated structure, leading to SIGSEGV.

I've also removed the check for an empty fd_set. It was broken before and will
never have fired, but I don't think it makes sense to fix it, given this race
condition.

The race can't be fixed because the implementation is documented to close the
socket channel and *then* cancel the selection key.

This patch also removes various dead functions and tidies up timeval usage.

Bug: 2093094
libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp