[9] RFR of 8132652: Java_sun_nio_ch_Net_poll passes a long to an int

Brian Burkhalter brian.burkhalter at oracle.com
Fri Jul 31 01:19:10 UTC 2015


Please review at your convenience.

Issue:	https://bugs.openjdk.java.net/browse/JDK-8132652
Diff:		

--- a/src/java.base/unix/native/libnio/ch/Net.c
+++ b/src/java.base/unix/native/libnio/ch/Net.c
@@ -25,14 +25,15 @@
 
 #include <sys/poll.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <string.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#include <limits.h>
 
 #include "jni.h"
 #include "jni_util.h"
 #include "jvm.h"
 #include "jlong.h"
 #include "sun_nio_ch_Net.h"
 #include "net_util.h"
@@ -705,15 +706,20 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlong timeout)
 {
     struct pollfd pfd;
     int rv;
     pfd.fd = fdval(env, fdo);
     pfd.events = events;
-    rv = poll(&pfd, 1, timeout);
+    if (timeout < INT_MIN) {
+        timeout = INT_MIN;
+    } else if (timeout > INT_MAX) {
+        timeout = INT_MAX;
+    }
+    rv = poll(&pfd, 1, (int)timeout);
 
     if (rv >= 0) {
         return pfd.revents;
     } else if (errno == EINTR) {
         return IOS_INTERRUPTED;
     } else {
         handleSocketError(env, errno);

Summary: While the jlong value passed as the parameter ‘timeout’ appears in all cases to be a widened jint and therefore that there is really no problem at present, clamping the jlong to the range of int might avert unforeseen future problems should the calling logic change.

Thanks,

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20150730/47b143c9/attachment.html>


More information about the nio-dev mailing list