CTS test for Android Security b/141890807

Bug: 141890807
Bug: 144322017
Test: Ran the new testcase on android-8.0.0_r2 with/without patch

Change-Id: Ibaad31f70e1e8ae2fd224fc5b72194c99099ae0f
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index e5d1581..1581fbe 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -233,6 +233,11 @@
         <option name="push" value="CVE-2019-9313->/data/local/tmp/CVE-2019-9313" />
 
         <!--__________________-->
+        <!-- Bulletin 2020-01 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2020-0007->/data/local/tmp/CVE-2020-0007" />
+
+        <!--__________________-->
         <!-- Bulletin 2020-03 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="CVE-2020-0069->/data/local/tmp/CVE-2020-0069" />
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/Android.bp
new file mode 100644
index 0000000..269c91e
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/Android.bp
@@ -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.
+ *
+ */
+
+cc_test {
+    name: "CVE-2020-0007",
+    defaults: ["cts_hostsidetests_securitybulletin_defaults"],
+    srcs: [
+        "poc.cpp",
+        ":cts_hostsidetests_securitybulletin_memutils_track",
+    ],
+    shared_libs: [
+        "libsensor",
+    ],
+    cflags: [
+        "-DCHECK_UNINITIALIZED_MEMORY",
+        "-DENABLE_SELECTIVE_OVERLOADING",
+    ],
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/poc.cpp
new file mode 100644
index 0000000..78259bc
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0007/poc.cpp
@@ -0,0 +1,64 @@
+/**
+ * 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 "../includes/common.h"
+#include "../includes/memutils_track.h"
+#include "hardware/sensors.h"
+#include "sensor/Sensor.h"
+#include "stdlib.h"
+
+size_t vulnerableSize = 0;
+
+using namespace android;
+char enable_selective_overload = ENABLE_NONE;
+
+bool is_tracking_required(size_t size) { return (size == vulnerableSize); }
+
+static sensor_t getTestSensorT() {
+  sensor_t hwSensor = {};
+  hwSensor.name = "Test ";
+  hwSensor.vendor = hwSensor.name;
+  hwSensor.version = 1;
+  hwSensor.handle = 2;
+  hwSensor.type = SENSOR_TYPE_ACCELEROMETER;
+  hwSensor.maxRange = 10.f;
+  hwSensor.resolution = 1.f;
+  hwSensor.power = 5.f;
+  hwSensor.minDelay = 1000;
+  hwSensor.fifoReservedEventCount = 50;
+  hwSensor.fifoMaxEventCount = 100;
+  hwSensor.stringType = SENSOR_STRING_TYPE_ACCELEROMETER;
+  hwSensor.requiredPermission = "";
+  hwSensor.maxDelay = 5000;
+  hwSensor.flags = SENSOR_FLAG_CONTINUOUS_MODE;
+  return hwSensor;
+}
+
+int main() {
+  sensor_t hwSensor = getTestSensorT();
+  Sensor sensor1(&hwSensor, SENSORS_DEVICE_API_VERSION_1_4);
+  vulnerableSize = sensor1.getFlattenedSize();
+  enable_selective_overload = ENABLE_MALLOC_CHECK;
+  void *buffer = malloc(vulnerableSize);
+  if (!buffer) {
+    return EXIT_FAILURE;
+  }
+  enable_selective_overload = ENABLE_NONE;
+  sensor1.flatten(buffer, vulnerableSize);
+  int status = is_memory_uninitialized();
+  free(buffer);
+  return status;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index df3bb5a..8e2cbca 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -45,6 +45,16 @@
      ******************************************************************************/
 
     /**
+     * b/141890807
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     */
+    @SecurityTest(minPatchLevel = "2020-01")
+    @Test
+    public void testPocCVE_2020_0007() throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2020-0007", null, getDevice());
+    }
+
+    /**
      * b/118372692
      * Vulnerability Behaviour: SIGSEGV in self
      */