8132652: Java_sun_nio_ch_Net_poll passes a long to an int
authorbpb
Mon, 03 Aug 2015 10:25:38 -0700
changeset 32014 262d30f45454
parent 32013 e7ad0380f7be
child 32015 eda394dcd1aa
child 32134 91e37aced110
8132652: Java_sun_nio_ch_Net_poll passes a long to an int Summary: Clamp long timeout parameter to [-1,INT_MAX]. Reviewed-by: alanb
jdk/src/java.base/unix/native/libnio/ch/Net.c
--- a/jdk/src/java.base/unix/native/libnio/ch/Net.c	Mon Aug 03 09:25:02 2015 +0800
+++ b/jdk/src/java.base/unix/native/libnio/ch/Net.c	Mon Aug 03 10:25:38 2015 -0700
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#include <limits.h>
 
 #include "jni.h"
 #include "jni_util.h"
@@ -709,7 +710,12 @@
     int rv;
     pfd.fd = fdval(env, fdo);
     pfd.events = events;
-    rv = poll(&pfd, 1, timeout);
+    if (timeout < -1) {
+        timeout = -1;
+    } else if (timeout > INT_MAX) {
+        timeout = INT_MAX;
+    }
+    rv = poll(&pfd, 1, (int)timeout);
 
     if (rv >= 0) {
         return pfd.revents;