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
diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java
index 6caf076..e8691bb 100644
--- a/opengl/tools/glgen/src/JniCodeEmitter.java
+++ b/opengl/tools/glgen/src/JniCodeEmitter.java
@@ -985,6 +985,7 @@
boolean emitExceptionCheck = ((numArrays > 0 || numStrings > 0)
&& (hasNonConstArg(jfunc, cfunc, nonPrimitiveArgs)
|| (cfunc.hasPointerArg() && numArrays > 0))
+ || (numBufferArgs > 0)
|| hasCheckTest(cfunc)
|| hasIfTest(cfunc))
|| (stringArgs.size() > 0);
@@ -1308,6 +1309,8 @@
out.println();
} else if (jfunc.getArgType(idx).isBuffer()) {
+ needsExit = needsExit || (!nullAllowed && !isPointerFunc);
+
String array = numBufferArgs <= 1 ? "_array" :
"_" + cfunc.getArgName(cIndex) + "Array";
String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" :
@@ -1318,6 +1321,17 @@
out.println(indent + "if (" + cname + "_buf) {");
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) {
out.println(indent +
diff --git a/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.cpp b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.cpp
new file mode 100644
index 0000000..3eacf3c
--- /dev/null
+++ b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.cpp
@@ -0,0 +1,9 @@
+/* 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);
+}
+
diff --git a/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.java b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.java
index bc6740e..1750b32 100644
--- a/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.java
+++ b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.java
@@ -7,4 +7,5 @@
int pixmap,
int[] attrib_list,
int offset
- );
\ No newline at end of file
+ );
+
diff --git a/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.nativeReg b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.nativeReg
new file mode 100644
index 0000000..fa260d8
--- /dev/null
+++ b/opengl/tools/glgen/stubs/egl/eglCreatePixmapSurface.nativeReg
@@ -0,0 +1 @@
+{"eglCreatePixmapSurface", "(Landroid/opengl/EGLDisplay;Landroid/opengl/EGLConfig;I[II)Landroid/opengl/EGLSurface;", (void *) android_eglCreatePixmapSurface },