[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
Change-Id: Id9027989d1024236d2c88af9964a75908d5571ff
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index aaecba5..ab54656 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -187,6 +187,11 @@
         <option name="push" value="CVE-2018-9424->/data/local/tmp/CVE-2018-9424" />
 
         <!--__________________-->
+        <!-- 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" />
+
+        <!--__________________-->
         <!-- Bulletin 2018-10 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="CVE-2018-9515->/data/local/tmp/CVE-2018-9515" />
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.bp
new file mode 100644
index 0000000..97fdf58
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9472/Android.bp
@@ -0,0 +1,29 @@
+// 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.
+
+cc_test {
+    name: "CVE-2018-9472",
+    defaults: ["cts_hostsidetests_securitybulletin_defaults"],
+    srcs: [
+        "poc.cpp",
+    ],
+    shared_libs: [
+        "liblog",
+        "libxml2",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
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 515aa4e..20766ab 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -41,6 +41,17 @@
      ******************************************************************************/
 
     /**
+     * b/79662501
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     */
+    @SecurityTest(minPatchLevel = "2018-09")
+    @Test
+    public void testPocCVE_2018_9472() throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2018-9472", null, getDevice());
+    }
+
+    /**
+     * CTS test for Android Security b/79662501
      * b/36554207
      * Vulnerability Behaviour: SIGSEGV in self
      **/