Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7969999d authored by Romain Guy's avatar Romain Guy
Browse files

Add null checks for *Buffer params

This change prevents crashes in native layers and throws an exception
instead.

Bug: 25695785
Test: CtsGraphicsTestCases
Change-Id: Ib6e6b7a09a86d8bc01a1c10ddd1af44f54d79ee8
parent 8adc012b
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -985,6 +985,7 @@ public class JniCodeEmitter {
        boolean emitExceptionCheck = ((numArrays > 0 || numStrings > 0)
        boolean emitExceptionCheck = ((numArrays > 0 || numStrings > 0)
                                             && (hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs)
                                             && (hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs)
                                                 || (cfunc.hasPointerArg() && numArrays > 0))
                                                 || (cfunc.hasPointerArg() && numArrays > 0))
                                         || (numBufferArgs > 0)
                                         || hasCheckTest(cfunc)
                                         || hasCheckTest(cfunc)
                                         || hasIfTest(cfunc))
                                         || hasIfTest(cfunc))
                                         || (stringArgs.size() > 0);
                                         || (stringArgs.size() > 0);
@@ -1308,6 +1309,8 @@ public class JniCodeEmitter {


                    out.println();
                    out.println();
                } else if (jfunc.getArgType(idx).isBuffer()) {
                } else if (jfunc.getArgType(idx).isBuffer()) {
                    needsExit = needsExit || (!nullAllowed && !isPointerFunc);

                    String array = numBufferArgs <= 1 ? "_array" :
                    String array = numBufferArgs <= 1 ? "_array" :
                        "_" + cfunc.getArgName(cIndex) + "Array";
                        "_" + cfunc.getArgName(cIndex) + "Array";
                    String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" :
                    String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" :
@@ -1318,6 +1321,17 @@ public class JniCodeEmitter {
                        out.println(indent + "if (" + cname + "_buf) {");
                        out.println(indent + "if (" + cname + "_buf) {");
                        out.print(indent);
                        out.print(indent);
                    }
                    }
                    else
                    {
                        out.println(indent + "if (!" + cname + "_buf) {");
                        out.println(indent + indent + "_exception = 1;");
                        out.println(indent + indent + "_exceptionType = " +
                                "\"java/lang/IllegalArgumentException\";");
                        out.println(indent + indent + "_exceptionMessage = \"" +
                                cname +" == null\";");
                        out.println(indent + indent + "goto exit;");
                        out.println(indent + "}");
                    }


                    if (isPointerFunc) {
                    if (isPointerFunc) {
                        out.println(indent +
                        out.println(indent +
+9 −0
Original line number Original line Diff line number Diff line
/* EGLSurface eglCreatePixmapSurface ( EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list ) */
static jobject
android_eglCreatePixmapSurface
  (JNIEnv *_env, jobject _this, jobject dpy, jobject config, jint pixmap, jintArray attrib_list_ref, jint offset) {
    jniThrowException(_env, "java/lang/UnsupportedOperationException",
        "eglCreatePixmapSurface");
    return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, (EGLSurface) 0);
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -8,3 +8,4 @@
        int[] attrib_list,
        int[] attrib_list,
        int offset
        int offset
    );
    );
+1 −0
Original line number Original line Diff line number Diff line
{"eglCreatePixmapSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePixmapSurface },