[RESTRICT AUTOMERGE] CTS test for Android Security b/111210196

Bug: 111210196
Bug: 143368277
Test: Ran the new testcase on android-8.0.0_r11 to test with/without patch

Merged-In: I6b95a2a2db1cb95460b7cb2ef9ae44d7206c92c5
Change-Id: I6b95a2a2db1cb95460b7cb2ef9ae44d7206c92c5
(cherry picked from commit 1054364c9b096a7ab403c6b45f482b3b7d9113f8)
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index 7b57a1b..4984b1f 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -245,6 +245,10 @@
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="CVE-2019-2184->/data/local/tmp/CVE-2019-2184" />
 
+        <!-- Bulletin 2019-12 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2019-2228->/data/local/tmp/CVE-2019-2228" />
+
         <!--__________________-->
         <!-- Bulletin 2020-01 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
diff --git a/hostsidetests/securitybulletin/res/cve_2019_2228_ipp.mp4 b/hostsidetests/securitybulletin/res/cve_2019_2228_ipp.mp4
new file mode 100644
index 0000000..d8f7d4e
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2019_2228_ipp.mp4
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/Android.mk
new file mode 100644
index 0000000..a8df1fb
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2020 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := CVE-2019-2228
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES := external/libcups/cups
+LOCAL_SHARED_LIBRARIES := libcups
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts sts vts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS := -Wall -Werror
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/poc.c b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/poc.c
new file mode 100644
index 0000000..b55c6f6
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2228/poc.c
@@ -0,0 +1,83 @@
+/**
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <fcntl.h>
+#include <ipp.h>
+#include <dlfcn.h>
+#include "../includes/common.h"
+
+int isInitialized = 0;
+void *check_ptr = NULL;
+size_t text_len = sizeof("text/plain") - 1;
+
+static void* (*real_malloc)(size_t) = NULL;
+static int (*real_strcmp)(const char* str1, const char* str2) = NULL;
+
+void init(void) {
+    real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc");
+    if (real_malloc == NULL) {
+        return;
+    }
+    real_strcmp = (int (*)(const char *, const char *))dlsym(RTLD_NEXT, "strcmp");
+    if (real_strcmp == NULL) {
+        return;
+    }
+    isInitialized = 1;
+}
+
+void *malloc(size_t size) {
+    if (!isInitialized) {
+        init();
+    }
+    void *tmp = real_malloc(size);
+    if (size == text_len) {
+        check_ptr = tmp;
+    }
+    return tmp;
+}
+
+int strcmp(const char* str1, const char* str2) {
+    if (!isInitialized) {
+        init();
+    }
+    if ((str1 == check_ptr) && (str1[text_len - 1] != '\0')) {
+        exit(EXIT_VULNERABLE);
+    }
+    return real_strcmp(str1, str2);
+}
+
+int main(int argc, char **argv) {
+    if (argc < 2) {
+        return EXIT_FAILURE;
+    }
+
+    int file_desc = open((const char *) argv[1], O_RDONLY);
+    if (file_desc < 0) {
+        return EXIT_FAILURE;
+    }
+
+    ipp_t *job = ippNew();
+    if(!job) {
+        return EXIT_FAILURE;
+    }
+    ippReadFile(file_desc, job);
+
+    if(job) {
+        free(job);
+    }
+    close(file_desc);
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 4556c67..a45b59f 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -54,6 +54,18 @@
      ******************************************************************************/
 
     /**
+     * b/111210196
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     */
+    @Test
+    @SecurityTest(minPatchLevel = "2019-12")
+    public void testPocCVE_2019_2228() throws Exception {
+        String inputFiles[] = {"cve_2019_2228_ipp.mp4"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2019-2228",
+                AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+    }
+
+    /**
      * b/157650336
      * Vulnerability Behaviour: SIGSEGV in self / EXIT_VULNERABLE (113)
      */