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

Bug: 120664978
Bug: 126802919
Test: Ran the new testcase on android-8.1.0_r1 to test with/without patch

Change-Id: Id267175fffd99f7b48c64e4508085ab486655984
(cherry picked from commit 1c87c1716d1deac2a554f819d5e63c64d5d24812)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/Android.mk
new file mode 100644
index 0000000..b035132
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/Android.mk
@@ -0,0 +1,37 @@
+# Copyright (C) 2021 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-2016
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_SRC_FILES += ../includes/memutils.c
+LOCAL_MULTILIB := 64
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES_64 := system/nfc/src/nfa/include/
+LOCAL_C_INCLUDES_64 += system/nfc/src/gki/common/
+LOCAL_C_INCLUDES_64 += system/nfc/src/include/
+LOCAL_C_INCLUDES_64 += system/nfc/src/gki/ulinux/
+LOCAL_C_INCLUDES_64 += system/nfc/src/nfc/include/
+LOCAL_C_INCLUDES_64 += system/nfc/src/hal/include/
+LOCAL_SHARED_LIBRARIES_64 := libnfc-nci
+
+# 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 -DCHECK_OVERFLOW
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/poc.cpp
new file mode 100644
index 0000000..4918f7a
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2016/poc.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 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 <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <nfa_api.h>
+
+void* GKI_getbuf(uint16_t size) {
+  void* ptr = malloc(size);
+  if (ptr) {
+    memset(ptr, 0x0, size);
+  }
+  return ptr;
+}
+
+void GKI_freebuf(void* p_buf) {
+  if (p_buf) {
+    free(p_buf);
+  }
+}
+
+int main() {
+  uint8_t* p_raw_data = (uint8_t*)malloc(sizeof(uint8_t) * 4);
+  uint16_t data_len = USHRT_MAX, presence_check_start_delay = 1;
+  NFA_SendRawFrame(p_raw_data, data_len, presence_check_start_delay);
+  free(p_raw_data);
+
+  return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2016.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2016.java
new file mode 100644
index 0000000..b66a357
--- /dev/null
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2016.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package android.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class CVE_2019_2016 extends SecurityTestCase {
+
+    /**
+     * b/120664978
+     * Vulnerability Behaviour: SIGSEGV in self
+     */
+    @SecurityTest(minPatchLevel = "2019-03")
+    @Test
+    public void testPocCVE_2019_2016() throws Exception {
+        pocPusher.only64();
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2019-2016", null, getDevice());
+    }
+}