diff options
author | Elliott Hughes <enh@google.com> | 2010-03-31 18:34:53 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-03-31 23:56:59 -0700 |
commit | de816ccf0d96c9fd9a042f4f8beaafee86ca02e7 (patch) | |
tree | 980f655646e67f52eb61ac1c68d924d788a78dd1 /luni | |
parent | ba6fad59410d74c4dbb19715dea6f5ea09a4b14c (diff) | |
download | libcore-de816ccf0d96c9fd9a042f4f8beaafee86ca02e7.zip libcore-de816ccf0d96c9fd9a042f4f8beaafee86ca02e7.tar.gz libcore-de816ccf0d96c9fd9a042f4f8beaafee86ca02e7.tar.bz2 |
Fix an off-by-one error in fd range checking.
Change-Id: I15f932bc246ebc7fec9471a873bef8bd58ef15fc
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp index 2344d14..f3ba44a 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp @@ -2212,6 +2212,10 @@ static jint osNetworkSystem_sendDatagram2(JNIEnv* env, jobject, return totalBytesSent; } +static bool isValidFd(int fd) { + return fd >= 0 && fd < FD_SETSIZE; +} + static bool initFdSet(JNIEnv* env, jobjectArray fdArray, jint count, fd_set* fdSet, int* maxFd) { for (int i = 0; i < count; ++i) { jobject fileDescriptor = env->GetObjectArrayElement(fdArray, i); @@ -2220,7 +2224,7 @@ static bool initFdSet(JNIEnv* env, jobjectArray fdArray, jint count, fd_set* fdS } const int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); - if (fd < 0 || fd > 1024) { + if (!isValidFd(fd)) { LOGE("selectImpl: ignoring invalid fd %i", fd); continue; } @@ -2248,9 +2252,7 @@ static bool translateFdSet(JNIEnv* env, jobjectArray fdArray, jint count, fd_set } const int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); - const bool valid = fd >= 0 && fd < 1024; - - if (valid && FD_ISSET(fd, &fdSet)) { + if (isValidFd(fd) && FD_ISSET(fd, &fdSet)) { flagArray[i + offset] = op; } else { flagArray[i + offset] = SOCKET_OP_NONE; |