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

Bug: 79662501
Bug: 113527084
Test: Ran the new testcase on android-8.1.0_r45 with/without patch

Merged-in: Ie6136b851927749182fb1af6410c756cb2b2e5ac
Change-Id: Ie2c4d6b62922b1c94badacec10379df7dd5cab5d
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index 136f44e..11ebdef 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -208,6 +208,7 @@
         <!--__________________-->
         <!-- Bulletin 2018-09 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2018-9472->/data/local/tmp/CVE-2018-9472" />
         <option name="push" value="CVE-2018-11261->/data/local/tmp/CVE-2018-11261" />
 
         <!--__________________-->
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.mk
new file mode 100644
index 0000000..4c883b8
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.mk
@@ -0,0 +1,34 @@
+# 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-2018-9472
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES := external/libxml2/include/
+LOCAL_C_INCLUDES += external/icu/icu4c/source/common/
+LOCAL_SHARED_LIBRARIES :=  liblog
+LOCAL_SHARED_LIBRARIES +=  libxml2
+
+# 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-2018-9472/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/poc.cpp
new file mode 100644
index 0000000..42f9323
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/poc.cpp
@@ -0,0 +1,50 @@
+/**
+ * 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 <dlfcn.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libxml/xmlmemory.h>
+#include "../includes/common.h"
+
+bool s_strlen_initialized = false;
+static unsigned long (*real_strlen)(const char *) = nullptr;
+
+#define TEST_STRING "CVE-2018_9472_Simulate_OverFlow_By_Large_String_Length"
+#define LARGE_SIZE  ((size_t) -2)
+
+void strlen_init(void) {
+    real_strlen = (unsigned long (*)(const char *)) dlsym(RTLD_NEXT, "strlen");
+    if (real_strlen) {
+        s_strlen_initialized = true;
+    }
+}
+
+size_t strlen(const char *str) {
+    if (!s_strlen_initialized) {
+        strlen_init();
+    }
+    if (!strncmp(str, TEST_STRING, sizeof(TEST_STRING))) {
+        return LARGE_SIZE;
+    }
+    return real_strlen(str);
+}
+
+int main() {
+    if (xmlMemStrdupLoc(TEST_STRING, "none", 0)) {
+        return EXIT_VULNERABLE;
+    }
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 3ce50f4..b078dac 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -51,6 +51,15 @@
      ******************************************************************************/
 
     /**
+     * b/79662501
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     */
+    @SecurityTest(minPatchLevel = "2018-09")
+    public void testPocCVE_2018_9472() throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2018-9472", null, getDevice());
+    }
+
+    /**
      * b/127702368
      * Vulnerability Behaviour: EXIT_VULNERABLE (113)
      */