United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-2200109 (porting) Bounds checks in io_util.c rely on undefined behaviour
JDK-2200109 : (porting) Bounds checks in io_util.c rely on undefined behaviour

Details
Type:
Backport
Submit Date:
2010-09-27
Status:
Resolved
Updated Date:
2011-04-20
Project Name:
JDK
Resolved Date:
2011-04-20
Component:
core-libs
OS:
Sub-Component:
java.io
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
Fixed Versions:
6u25-rev (b21)

Related Reports
Backport:

Sub Tasks

Description
                                    

Comments
EVALUATION

Please see the parent CR. 

Suggested Fix:

--- a/src/share/native/java/io/io_util.c        Wed Dec 10 14:03:15 2008 -0800
+++ b/src/share/native/java/io/io_util.c        Tue Dec 23 20:07:06 2008 +0000
@@ -74,8 +74,7 @@ readBytes(JNIEnv *env, jobject this, jby
     }
     datalen = (*env)->GetArrayLength(env, bytes);

-    if ((off < 0) || (off > datalen) ||
-        (len < 0) || ((off + len) > datalen) || ((off + len) < 0)) {
+    if ((off < 0) || (len < 0) || (len > (datalen - off))) {
         JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0);
         return -1;
     }
@@ -147,8 +146,7 @@ writeBytes(JNIEnv *env, jobject this, jb
     }
     datalen = (*env)->GetArrayLength(env, bytes);

-    if ((off < 0) || (off > datalen) ||
-        (len < 0) || ((off + len) > datalen) || ((off + len) < 0)) {
+    if ((off < 0) || (len < 0) || (len > (datalen - off))) {
         JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0);
         return;
     }
                                     
2011-02-17



Hardware and Software, Engineered to Work Together