8129897: Old verifier fails to reject erroneous cast from boolean[] to byte[]
authorhseigel
Thu, 23 Jul 2015 08:44:37 -0400
changeset 32021 5778b37712f4
parent 31910 64d8434c9d85
child 32022 c692b17ea891
8129897: Old verifier fails to reject erroneous cast from boolean[] to byte[] Summary: Add ITEM_Boolean enum to differentiate between arrays of booleans and arrays of bytes Reviewed-by: dholmes, lfoltan
jdk/src/java.base/share/native/libverify/check_code.c
--- a/jdk/src/java.base/share/native/libverify/check_code.c	Tue Jul 21 20:37:19 2015 +0200
+++ b/jdk/src/java.base/share/native/libverify/check_code.c	Thu Jul 23 08:44:37 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -159,11 +159,12 @@
     ITEM_InitObject,            /* "this" is init method, before call
                                     to super() */
     ITEM_ReturnAddress,         /* Extra info gives instr # of start pc */
-    /* The following three are only used within array types.
+    /* The following four are only used within array types.
      * Normally, we use ITEM_Integer, instead. */
     ITEM_Byte,
     ITEM_Short,
-    ITEM_Char
+    ITEM_Char,
+    ITEM_Boolean
 };
 
 
@@ -1446,7 +1447,9 @@
                 full_info = MAKE_FULLINFO(ITEM_Float, 1, 0); break;
             case JVM_T_DOUBLE:
                 full_info = MAKE_FULLINFO(ITEM_Double, 1, 0); break;
-            case JVM_T_BYTE: case JVM_T_BOOLEAN:
+            case JVM_T_BOOLEAN:
+                full_info = MAKE_FULLINFO(ITEM_Boolean, 1, 0); break;
+            case JVM_T_BYTE:
                 full_info = MAKE_FULLINFO(ITEM_Byte, 1, 0); break;
             case JVM_T_CHAR:
                 full_info = MAKE_FULLINFO(ITEM_Char, 1, 0); break;
@@ -2250,10 +2253,11 @@
                         break;
                     }
 
-                    case 'B':   /* array of bytes */
-                        if (top_type != MAKE_FULLINFO(ITEM_Byte, 1, 0))
+                    case 'B':    /* array of bytes or booleans */
+                        if (top_type != MAKE_FULLINFO(ITEM_Byte, 1, 0) &&
+                            top_type != MAKE_FULLINFO(ITEM_Boolean, 1, 0))
                             CCerror(context,
-                                  "Expecting to find array of bytes on stack");
+                                  "Expecting to find array of bytes or Booleans on stack");
                         break;
 
                     case 'C':   /* array of characters */
@@ -3728,7 +3732,14 @@
                 result = 0;
                 break;
 
-            case JVM_SIGNATURE_BOOLEAN: case JVM_SIGNATURE_BYTE:
+            case JVM_SIGNATURE_BOOLEAN:
+                full_info = (array_depth > 0)
+                              ? MAKE_FULLINFO(ITEM_Boolean, 0, 0)
+                              : MAKE_FULLINFO(ITEM_Integer, 0, 0);
+                result = 'I';
+                break;
+
+            case JVM_SIGNATURE_BYTE:
                 full_info = (array_depth > 0)
                               ? MAKE_FULLINFO(ITEM_Byte, 0, 0)
                               : MAKE_FULLINFO(ITEM_Integer, 0, 0);
@@ -3831,7 +3842,7 @@
         int indirection = GET_INDIRECTION(array_info) - 1;
         int extra_info = GET_EXTRA_INFO(array_info);
         if (   (indirection == 0)
-               && ((type == ITEM_Short || type == ITEM_Byte || type == ITEM_Char)))
+               && ((type == ITEM_Short || type == ITEM_Byte || type == ITEM_Boolean || type == ITEM_Char)))
             type = ITEM_Integer;
         return MAKE_FULLINFO(type, indirection, extra_info);
     }
@@ -4286,6 +4297,8 @@
             jio_fprintf(stdout, "C"); break;
         case ITEM_Short:
             jio_fprintf(stdout, "S"); break;
+        case ITEM_Boolean:
+            jio_fprintf(stdout, "Z"); break;
         case ITEM_Byte:
             jio_fprintf(stdout, "B"); break;
         case ITEM_NewObject: