Static type vulnerabilities caused by array covariance

Source: Internet
Author: User
Tags modifiers

In a previous example of a Java bytecode checksum, we saw that the JVM would validate the. class file it loads to ensure type safety. In Java, however, there is a case where the bytecode checksum of the compiler and the JVM cannot be detected, and the error that is to be discovered when it is actually run is the type of static system vulnerability caused by the covariance of the array.

Or, like the previous post, use ASM to generate bytecode:

Java code

Import Java.io.FileOutputStream;
Import Org.objectweb.asm.ClassWriter;
Import Org.objectweb.asm.MethodVisitor;

Import Org.objectweb.asm.Opcodes; public class Testasm implements opcodes {public static void main (string[] args) throws Exception {Classwrite
        R cw = new Classwriter (0);
            Cw.visit (v1_5,//class format version acc_public,//class modifiers
            ' Testverification ',//class name fully qualified name NULL,//generic signature
        "Java/lang/object",//Super class fully qualified name new string[] {}//implemented interfaces
        
        );                    Methodvisitor mv = Cw.visitmethod (acc_public + acc_static,//access modifiers "main",                     Method Name "([ljava/lang/string;) V",//Description NULL,                   Generic signature NULL   exceptions);
        Mv.visitcode ();
        MV.VISITINSN (iconst_1);
        MV.VISITTYPEINSN (Anewarray, "java/lang/float");
        MV.VISITTYPEINSN (Checkcast, "[Ljava/lang/object;");
        MV.VISITVARINSN (ASTORE, 0);
        MV.VISITVARINSN (aload, 0);
        MV.VISITINSN (ICONST_0);
        MV.VISITLDCINSN ("a string");
        MV.VISITINSN (Aastore);
        MV.VISITVARINSN (aload, 0);
        MV.VISITINSN (ICONST_0);
        MV.VISITINSN (Aaload);
        MV.VISITMETHODINSN (invokevirtual, "Java/lang/object", "toString", "() V");
        MV.VISITINSN (return);
        MV.VISITMAXS (3, 1); Mv.visitend (); End Method Cw.visitend ();
        End Class byte[] Clz = Cw.tobytearray ();
        FileOutputStream out = new FileOutputStream ("Testverification.class");
        Out.write (CLZ);
    Out.close (); }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.