Updated AdbUtils.java and memutils file

Added functions in AdbUtils.java which enable testing for both hangs and crashes
Updated memutils file to support different configurations

Bug: 147497306
Test: none

Change-Id: I554ac7674317cf203206411b69e6e4ef31883e75
Merged-In: I554ac7674317cf203206411b69e6e4ef31883e75
diff --git a/hostsidetests/securitybulletin/securityPatch/includes/memutils.c b/hostsidetests/securitybulletin/securityPatch/includes/memutils.c
index 10df3bd..d5b6884 100644
--- a/hostsidetests/securitybulletin/securityPatch/includes/memutils.c
+++ b/hostsidetests/securitybulletin/securityPatch/includes/memutils.c
@@ -24,7 +24,7 @@
 #include <signal.h>
 #include "memutils.h"
 
-void sigsegv_handler(int signum) {
+void exit_handler(void) {
     size_t page_size = getpagesize();
     for (int i = 0; i < s_mem_map_index; i++) {
         if (NULL != s_mem_map[i].start_ptr) {
@@ -32,12 +32,27 @@
                               (s_mem_map[i].num_pages * page_size));
         }
     }
-    (*old_sa.sa_handler)(signum);
+#ifdef CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE
+    for (int i = 0; i < MAX_ENTRIES; i++) {
+        if (NULL != s_free_list[i].start_ptr) {
+            ENABLE_MEM_ACCESS(s_free_list[i].start_ptr,
+                    (s_free_list[i].num_pages * page_size));
+            real_free(s_free_list[i].start_ptr);
+            memset(&s_free_list[i], 0, sizeof(map_struct_t));
+        }
+    }
+#endif /* CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE */
+}
+
+void sigsegv_handler(int signum, siginfo_t *info, void* context) {
+    exit_handler();
+    (*old_sa.sa_sigaction)(signum, info, context);
 }
 
 void sighandler_init(void) {
     sigemptyset(&new_sa.sa_mask);
-    new_sa.sa_handler = sigsegv_handler;
+    new_sa.sa_flags = SA_SIGINFO;
+    new_sa.sa_sigaction = sigsegv_handler;
     sigaction(SIGSEGV, &new_sa, &old_sa);
 }
 
@@ -46,12 +61,25 @@
     if (NULL == real_memalign) {
         return;
     }
+    real_calloc = dlsym(RTLD_NEXT, "calloc");
+    if (NULL == real_calloc) {
+        return;
+    }
+    real_malloc = dlsym(RTLD_NEXT, "malloc");
+    if (NULL == real_malloc) {
+        return;
+    }
+    real_realloc = dlsym(RTLD_NEXT, "realloc");
+    if (NULL == real_realloc) {
+        return;
+    }
     real_free = dlsym(RTLD_NEXT, "free");
     if (NULL == real_free) {
         return;
     }
     memset(&s_mem_map, 0, MAX_ENTRIES * sizeof(map_struct_t));
     sighandler_init();
+    atexit(exit_handler);
     s_memutils_initialized = 1;
 }
 
@@ -59,6 +87,11 @@
     if (s_memutils_initialized == 0) {
         memutils_init();
     }
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+    if ((enable_selective_overload & ENABLE_MEMALIGN_CHECK) != ENABLE_MEMALIGN_CHECK) {
+        return real_memalign(alignment, size);
+    }
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
     char* start_ptr;
     char* mem_ptr;
     size_t total_size;
@@ -101,35 +134,131 @@
     total_size = (num_pages * page_size);
     start_ptr = (char *) real_memalign(page_size, total_size);
 #ifdef CHECK_OVERFLOW
+#ifdef FORCE_UNALIGN
+    mem_ptr = (char *) start_ptr + ((num_pages - 1) * page_size) - size;
+#else
     mem_ptr = (char *) start_ptr + ((num_pages - 1) * page_size) - aligned_size;
+#endif /* FORCE_UNALIGN */
     DISABLE_MEM_ACCESS((start_ptr + ((num_pages - 1) * page_size)), page_size);
-#endif
+#endif /* CHECK_OVERFLOW */
 #ifdef CHECK_UNDERFLOW
     mem_ptr = (char *) start_ptr + page_size;
     DISABLE_MEM_ACCESS(start_ptr, page_size);
-#endif
+#endif /* CHECK_UNDERFLOW */
     s_mem_map[s_mem_map_index].start_ptr = start_ptr;
     s_mem_map[s_mem_map_index].mem_ptr = mem_ptr;
     s_mem_map[s_mem_map_index].num_pages = num_pages;
+    s_mem_map[s_mem_map_index].mem_size = size;
     s_mem_map_index++;
     memset(mem_ptr, INITIAL_VAL, size);
     return mem_ptr;
 }
 
+void *malloc(size_t size) {
+    if (s_memutils_initialized == 0) {
+        memutils_init();
+    }
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+    if ((enable_selective_overload & ENABLE_MALLOC_CHECK) != ENABLE_MALLOC_CHECK) {
+        return real_malloc(size);
+    }
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
+    return memalign(sizeof(size_t), size);
+}
+
+void *calloc(size_t nitems, size_t size) {
+    if (s_memutils_initialized == 0) {
+        memutils_init();
+    }
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+    if ((enable_selective_overload & ENABLE_CALLOC_CHECK) != ENABLE_CALLOC_CHECK) {
+        return real_calloc(nitems, size);
+    }
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
+    void *ptr = memalign(sizeof(size_t), (nitems * size));
+    if (ptr)
+        memset(ptr, 0, (nitems * size));
+    return ptr;
+}
+
+void *realloc(void *ptr, size_t size) {
+    if (s_memutils_initialized == 0) {
+        memutils_init();
+    }
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+    if ((enable_selective_overload & ENABLE_REALLOC_CHECK) != ENABLE_REALLOC_CHECK) {
+        return real_realloc(ptr, size);
+    }
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
+    if (ptr != NULL) {
+        int i = 0;
+        for (i = 0; i < s_mem_map_index; i++) {
+            if (ptr == s_mem_map[i].mem_ptr) {
+                void* temp = malloc(size);
+                if (temp == NULL) {
+                    return NULL;
+                }
+                if (s_mem_map[i].mem_size > size) {
+                    memcpy(temp, ptr, size);
+                } else {
+                    memcpy(temp, ptr, s_mem_map[i].mem_size);
+                }
+                free(s_mem_map[i].mem_ptr);
+                return temp;
+            }
+        }
+    }
+    return real_realloc(ptr, size);
+}
+
 void free(void *ptr) {
     if (s_memutils_initialized == 0) {
         memutils_init();
     }
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+    if ((enable_selective_overload & ENABLE_FREE_CHECK) != ENABLE_FREE_CHECK) {
+        return real_free(ptr);
+    }
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
     if (ptr != NULL) {
         int i = 0;
         size_t page_size = getpagesize();
         for (i = 0; i < s_mem_map_index; i++) {
             if (ptr == s_mem_map[i].mem_ptr) {
+#ifdef CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE
+                s_free_list[s_free_write_index].start_ptr =
+                s_mem_map[i].start_ptr;
+                s_free_list[s_free_write_index].mem_ptr = s_mem_map[i].mem_ptr;
+                s_free_list[s_free_write_index].num_pages =
+                s_mem_map[i].num_pages;
+                s_free_list[s_free_write_index].mem_size = s_mem_map[i].mem_size;
+                s_free_write_index++;
+                s_free_list_size += s_mem_map[i].mem_size;
+                DISABLE_MEM_ACCESS(s_mem_map[i].start_ptr,
+                        (s_mem_map[i].num_pages * page_size));
+                memset(&s_mem_map[i], 0, sizeof(map_struct_t));
+                while (s_free_list_size > CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE) {
+                    ENABLE_MEM_ACCESS(
+                            s_free_list[s_free_read_index].start_ptr,
+                            (s_free_list[s_free_read_index].num_pages * page_size));
+                    real_free(s_free_list[s_free_read_index].start_ptr);
+                    s_free_list_size -= s_free_list[s_free_read_index].mem_size;
+                    memset(&s_free_list[s_free_read_index], 0,
+                            sizeof(map_struct_t));
+                    s_free_read_index++;
+                    if ((s_free_read_index == MAX_ENTRIES)
+                            || (s_free_read_index >= s_free_write_index)) {
+                        break;
+                    }
+                }
+                return;
+#else
                 ENABLE_MEM_ACCESS(s_mem_map[i].start_ptr,
                                   (s_mem_map[i].num_pages * page_size));
                 real_free(s_mem_map[i].start_ptr);
                 memset(&s_mem_map[i], 0, sizeof(map_struct_t));
                 return;
+#endif /* CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE */
             }
         }
     }
diff --git a/hostsidetests/securitybulletin/securityPatch/includes/memutils.h b/hostsidetests/securitybulletin/securityPatch/includes/memutils.h
index ede8bb1..e054219 100644
--- a/hostsidetests/securitybulletin/securityPatch/includes/memutils.h
+++ b/hostsidetests/securitybulletin/securityPatch/includes/memutils.h
@@ -13,7 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#define MAX_ENTRIES        (1024)
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#define MAX_ENTRIES        (1024 * 1024)
 #define INITIAL_VAL        (0xBE)
 
 #define DISABLE_MEM_ACCESS(mem, size)\
@@ -22,18 +26,43 @@
 #define ENABLE_MEM_ACCESS(mem, size)\
     mprotect((char *) mem, size, PROT_READ | PROT_WRITE);
 
+#define ENABLE_NONE               0x00
+#define ENABLE_MEMALIGN_CHECK     0x01
+#define ENABLE_MALLOC_CHECK       0x02
+#define ENABLE_CALLOC_CHECK       0x04
+#define ENABLE_REALLOC_CHECK      0x08
+#define ENABLE_FREE_CHECK         0x10
+#define ENABLE_ALL                ENABLE_MEMALIGN_CHECK | ENABLE_MALLOC_CHECK |\
+    ENABLE_CALLOC_CHECK | ENABLE_REALLOC_CHECK | ENABLE_FREE_CHECK
+
 typedef struct _map_struct_t {
     void *start_ptr;
     void *mem_ptr;
     int num_pages;
+    size_t mem_size;
 } map_struct_t;
 
 static void* (*real_memalign)(size_t, size_t) = NULL;
+static void* (*real_calloc)(size_t, size_t) = NULL;
+static void* (*real_malloc)(size_t) = NULL;
+static void* (*real_realloc)(void *ptr, size_t size) = NULL;
 static void (*real_free)(void *) = NULL;
 static int s_memutils_initialized = 0;
 static int s_mem_map_index = 0;
 static struct sigaction new_sa, old_sa;
+#ifdef ENABLE_SELECTIVE_OVERLOADING
+extern char enable_selective_overload;
+#endif /* ENABLE_SELECTIVE_OVERLOADING */
+#ifdef CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE
+static int s_free_write_index = 0;
+static int s_free_read_index = 0;
+static int s_free_list_size = 0;
+map_struct_t s_free_list[MAX_ENTRIES];
+#endif /* CHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE */
 map_struct_t s_mem_map[MAX_ENTRIES];
 #if (!(defined CHECK_OVERFLOW) && !(defined CHECK_UNDERFLOW))
     #error "CHECK MACROS NOT DEFINED"
 #endif
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
diff --git a/hostsidetests/securitybulletin/securityPatch/includes/omxUtils.cpp b/hostsidetests/securitybulletin/securityPatch/includes/omxUtils.cpp
index 4e2db40..0c613ad 100644
--- a/hostsidetests/securitybulletin/securityPatch/includes/omxUtils.cpp
+++ b/hostsidetests/securitybulletin/securityPatch/includes/omxUtils.cpp
@@ -25,6 +25,7 @@
 int32_t mCurGeneration;
 List<omx_message> mMessageQueue;
 bool mUseTreble;
+int numCallbackEmptyBufferDone;
 
 struct CodecObserver : public BnOMXObserver {
  public:
@@ -39,11 +40,33 @@
     virtual ~CodecObserver() {
     }
 };
+struct DeathNotifier : public IBinder::DeathRecipient,
+        public ::android::hardware::hidl_death_recipient {
+    explicit DeathNotifier() {
+    }
+
+    virtual void binderDied(const wp<IBinder> &) {
+        ALOGE("Binder Died");
+        exit (EXIT_FAILURE);
+    }
+
+    virtual void serviceDied(
+            uint64_t /* cookie */,
+            const wp<::android::hidl::base::V1_0::IBase>& /* who */) {
+        ALOGE("Service Died");
+        exit (EXIT_FAILURE);
+    }
+};
+sp<DeathNotifier> mDeathNotifier;
 void handleMessages(int32_t gen, const std::list<omx_message> &messages) {
     Mutex::Autolock autoLock(mLock);
     for (std::list<omx_message>::const_iterator it = messages.cbegin();
             it != messages.cend();) {
-        mMessageQueue.push_back(*it++);
+        mMessageQueue.push_back(*it);
+        const omx_message &msg = *it++;
+        if (msg.type == omx_message::EMPTY_BUFFER_DONE) {
+            numCallbackEmptyBufferDone++;
+        }
         mLastMsgGeneration = gen;
     }
     mMessageAddedCondition.signal();
@@ -115,7 +138,23 @@
         mUseTreble = false;
     }
     sp<CodecObserver> observer = new CodecObserver(++mCurGeneration);
-    return mOMX->allocateNode(codecName, observer, &mOMXNode);
+    status_t ret = mOMX->allocateNode(codecName, observer, &mOMXNode);
+    if (ret == OK) {
+        mDeathNotifier = new DeathNotifier();
+        if (mUseTreble) {
+            auto tOmxNode = mOMXNode->getHalInterface();
+            if (tOmxNode != NULL) {
+                tOmxNode->linkToDeath(mDeathNotifier, 0);
+            } else {
+                ALOGE("No HAL Interface");
+                exit (EXIT_FAILURE);
+            }
+        } else {
+            IInterface::asBinder(mOMXNode)->linkToDeath(mDeathNotifier);
+        }
+    }
+    numCallbackEmptyBufferDone = 0;
+    return ret;
 }
 status_t omxUtilsGetParameter(int portIndex,
                               OMX_PARAM_PORTDEFINITIONTYPE *params) {
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/AdbUtils.java b/hostsidetests/securitybulletin/src/android/security/cts/AdbUtils.java
index 9e2be35..f74412d 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/AdbUtils.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/AdbUtils.java
@@ -34,6 +34,9 @@
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.Scanner;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.concurrent.Callable;
 
 import java.util.regex.Pattern;
 import java.lang.Thread;
@@ -42,6 +45,10 @@
 
 public class AdbUtils {
 
+    final static String TMP_PATH = "/data/local/tmp/";
+    final static int TIMEOUT_SEC = 9 * 60;
+    final static String RESOURCE_ROOT = "/";
+
     /** Runs a commandline on the specified device
      *
      * @param command the command to be ran
@@ -213,6 +220,40 @@
         }
     }
 
+    /**
+     * Pushes the specified files to the specified destination directory
+     *
+     * @param inputFiles files required as input
+     * @param inputFilesDestination destination directory to which input files are
+     *        pushed
+     * @param device device to be run on
+     */
+    public static void pushResources(String[] inputFiles, String inputFilesDestination,
+            ITestDevice device) throws Exception {
+        if ( (inputFiles != null) && (inputFilesDestination != null)) {
+            for (String tempFile : inputFiles) {
+                pushResource(RESOURCE_ROOT + tempFile, inputFilesDestination + tempFile, device);
+            }
+        }
+    }
+
+    /**
+     * Removes the specified files from the specified destination directory
+     *
+     * @param inputFiles files required as input
+     * @param inputFilesDestination destination directory where input files are
+     *        present
+     * @param device device to be run on
+     */
+    public static void removeResources(String[] inputFiles, String inputFilesDestination,
+            ITestDevice device) throws Exception {
+        if ( (inputFiles != null) && (inputFilesDestination != null)) {
+            for (String tempFile : inputFiles) {
+                runCommandLine("rm " + inputFilesDestination + tempFile, device);
+            }
+        }
+    }
+
    /**
      * Extracts the binary data from a resource and writes it to a temp file
      */
@@ -273,9 +314,22 @@
      */
     public static int runPocGetExitStatus(String pocName, ITestDevice device, int timeout)
             throws Exception {
-        device.executeShellCommand("chmod +x /data/local/tmp/" + pocName);
+       return runPocGetExitStatus(pocName, null, device, timeout);
+    }
+
+    /**
+     * Pushes and runs a binary to the device and returns the exit status.
+     * @param pocName a string path to poc from the /res folder
+     * @param arguments input arguments for the poc
+     * @param device device to be ran on
+     * @param timeout time to wait for output in seconds
+
+     */
+    public static int runPocGetExitStatus(String pocName, String arguments, ITestDevice device,
+            int timeout) throws Exception {
+        device.executeShellCommand("chmod +x " + TMP_PATH + pocName);
         CollectingOutputReceiver receiver = new CollectingOutputReceiver();
-        String cmd = "/data/local/tmp/" + pocName + " > /dev/null 2>&1; echo $?";
+        String cmd = TMP_PATH + pocName + " " + arguments + " > /dev/null 2>&1; echo $?";
         long time = System.currentTimeMillis();
         device.executeShellCommand(cmd, receiver, timeout, TimeUnit.SECONDS, 0);
         time = System.currentTimeMillis() - time;
@@ -297,8 +351,20 @@
      */
     public static void runPocAssertExitStatusNotVulnerable(
             String pocName, ITestDevice device, int timeout) throws Exception {
+        runPocAssertExitStatusNotVulnerable(pocName, null, device, timeout);
+    }
+
+    /**
+     * Pushes and runs a binary and asserts that the exit status isn't 113: vulnerable.
+     * @param pocName a string path to poc from the /res folder
+     * @param arguments input arguments for the poc
+     * @param device device to be ran on
+     * @param timeout time to wait for output in seconds
+     */
+    public static void runPocAssertExitStatusNotVulnerable(String pocName, String arguments,
+            ITestDevice device, int timeout) throws Exception {
         assertTrue("PoC returned exit status 113: vulnerable",
-                runPocGetExitStatus(pocName, device, timeout) != 113);
+                runPocGetExitStatus(pocName, arguments, device, timeout) != 113);
     }
 
     public static int runProxyAutoConfig(String pacName, ITestDevice device) throws Exception {
@@ -325,6 +391,99 @@
     }
 
     /**
+     * Runs the poc binary and asserts following 2 conditions.
+     *  1. There are no security crashes in the binary.
+     *  2. The exit status isn't 113 (Code 113 is used to indicate the vulnerability condition).
+     *
+     * @param binaryName name of the binary
+     * @param arguments arguments for running the binary
+     * @param device device to be run on
+     */
+    public static void runPocAssertNoCrashesNotVulnerable(String binaryName, String arguments,
+            ITestDevice device) throws Exception {
+        runPocAssertNoCrashesNotVulnerable(binaryName, arguments, null, null, device, null);
+    }
+
+    /**
+     * Runs the poc binary and asserts following 2 conditions.
+     *  1. There are no security crashes in the binary.
+     *  2. The exit status isn't 113 (Code 113 is used to indicate the vulnerability condition).
+     *
+     * @param binaryName name of the binary
+     * @param arguments arguments for running the binary
+     * @param device device to be run on
+     * @param processPatternStrings a Pattern string to match the crash tombstone
+     *        process
+     */
+    public static void runPocAssertNoCrashesNotVulnerable(String binaryName, String arguments,
+            ITestDevice device, String processPatternStrings[]) throws Exception {
+        runPocAssertNoCrashesNotVulnerable(binaryName, arguments, null, null, device,
+                processPatternStrings);
+    }
+
+    /**
+     * Runs the poc binary and asserts following 2 conditions.
+     *  1. There are no security crashes in the binary.
+     *  2. The exit status isn't 113 (Code 113 is used to indicate the vulnerability condition).
+     *
+     * @param binaryName name of the binary
+     * @param arguments arguments for running the binary
+     * @param inputFiles files required as input
+     * @param inputFilesDestination destination directory to which input files are
+     *        pushed
+     * @param device device to be run on
+     */
+    public static void runPocAssertNoCrashesNotVulnerable(String binaryName, String arguments,
+            String inputFiles[], String inputFilesDestination, ITestDevice device)
+            throws Exception {
+        runPocAssertNoCrashesNotVulnerable(binaryName, arguments, inputFiles, inputFilesDestination,
+                device, null);
+    }
+
+    /**
+     * Runs the poc binary and asserts following 3 conditions.
+     *  1. There are no security crashes in the binary.
+     *  2. There are no security crashes that match the expected process pattern.
+     *  3. The exit status isn't 113 (Code 113 is used to indicate the vulnerability condition).
+     *
+     * @param binaryName name of the binary
+     * @param arguments arguments for running the binary
+     * @param inputFiles files required as input
+     * @param inputFilesDestination destination directory to which input files are
+     *        pushed
+     * @param device device to be run on
+     * @param processPatternStrings a Pattern string to match the crash tombstone
+     *        process
+     */
+    public static void runPocAssertNoCrashesNotVulnerable(String binaryName, String arguments,
+            String inputFiles[], String inputFilesDestination, ITestDevice device,
+            String processPatternStrings[]) throws Exception {
+        pushResources(inputFiles, inputFilesDestination, device);
+        runCommandLine("logcat -c", device);
+        try {
+            runPocAssertExitStatusNotVulnerable(binaryName, arguments, device, TIMEOUT_SEC);
+        } catch (IllegalArgumentException e) {
+            /*
+             * Since 'runPocGetExitStatus' method raises IllegalArgumentException upon
+             * hang/timeout, catching the exception here and ignoring it. Hangs are of
+             * Moderate severity and hence patches may not be ported. This piece of code can
+             * be removed once 'runPocGetExitStatus' is updated to handle hangs.
+             */
+            CLog.w("Ignoring IllegalArgumentException: " + e);
+        } finally {
+            removeResources(inputFiles, inputFilesDestination, device);
+        }
+        List<String> processPatternList = new ArrayList<>();
+        if (processPatternStrings != null) {
+            processPatternList.addAll(Arrays.asList(processPatternStrings));
+        }
+        processPatternList.add(binaryName);
+        String[] processPatternStringsWithSelf = new String[processPatternList.size()];
+        processPatternList.toArray(processPatternStringsWithSelf);
+        assertNoCrashes(device, processPatternStringsWithSelf);
+    }
+
+    /**
      * Dumps logcat and asserts that there are no security crashes that match the expected process.
      * By default, checks min crash addresses
      * pattern. Ensure that adb logcat -c is called beforehand.
@@ -373,39 +532,4 @@
         }
         fail(error.toString());
     }
-
-    /**
-     * Executes a given poc within a given timeout. Returns error if the
-     * given poc doesnt complete its execution within timeout. It also deletes
-     * the list of files provided.
-     *
-     * @param runner the thread which will be run
-     * @param timeout the timeout within which the thread's execution should
-     *        complete
-     * @param device device to be ran on
-     * @param inputFiles list of files to be deleted
-     */
-    public static void runWithTimeoutDeleteFiles(Runnable runner, int timeout, ITestDevice device,
-            String[] inputFiles) throws Exception {
-        Thread t = new Thread(runner);
-        t.start();
-        boolean test_failed = false;
-        try {
-            t.join(timeout);
-        } catch (InterruptedException e) {
-            test_failed = true;
-        } finally {
-            if (inputFiles != null) {
-                for (String tempFile : inputFiles) {
-                    AdbUtils.runCommandLine("rm /data/local/tmp/" + tempFile, device);
-                }
-            }
-            if (test_failed) {
-                Assert.fail("PoC was interrupted");
-            }
-        }
-        if (t.isAlive()) {
-            Assert.fail("PoC not completed within timeout of " + timeout + " ms");
-        }
-    }
 }
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 761ea30..aabc21d 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -24,66 +24,33 @@
 @SecurityTest
 public class TestMedia extends SecurityTestCase {
 
-    final static int TIMEOUT_SEC = 9 * 60;
-    final static String RESOURCE_ROOT = "/";
-    final static String TMP_FILE_PATH = "/data/local/tmp/";
 
-    /****************************************************************
-     * To prevent merge conflicts, add tests for N below this comment,
-     * before any existing test methods
-     ****************************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add tests for N below this comment, before any
+     * existing test methods
+     ******************************************************************************/
 
     @SecurityTest(minPatchLevel = "2017-07")
     public void testPocCVE_2017_0684() throws Exception {
-        String processPatterns[] = {"media.codec", "media.swcodec"};
-        runMediaTest("CVE-2017-0684", null, null, getDevice(), processPatterns);
+        String processPatternStrings[] = {"mediaserver", "omx@1.0-service"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2017-0684", null, getDevice(),
+                processPatternStrings);
     }
 
-    /****************************************************************
-     * To prevent merge conflicts, add tests for O below this comment,
-     * before any existing test methods
-     ****************************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add tests for O below this comment, before any
+     * existing test methods
+     ******************************************************************************/
 
 
-    /****************************************************************
-     * To prevent merge conflicts, add tests for P below this comment,
-     * before any existing test methods
-     ****************************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add tests for P below this comment, before any
+     * existing test methods
+     ******************************************************************************/
 
-    /**
-     * Pushes input files, runs the PoC and checks for crash and hang
-     *
-     * @param binaryName name of the binary
-     * @param inputFiles files required as input
-     * @param arguments arguments for running the binary
-     * @param device device to be run on
-     * @param errPattern error patterns to be checked for
-     */
-    public static void runMediaTest(String binaryName,
-            String inputFiles[], String arguments, ITestDevice device,
-            String processPatternStrings[]) throws Exception {
-        if (inputFiles != null) {
-            for (String tempFile : inputFiles) {
-                AdbUtils.pushResource(RESOURCE_ROOT + tempFile,
-                        TMP_FILE_PATH + tempFile, device);
-            }
-        }
-        AdbUtils.runCommandLine("logcat -c", device);
-        AdbUtils.runWithTimeoutDeleteFiles(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    AdbUtils.runPocNoOutput(binaryName, device,
-                            TIMEOUT_SEC + 30, arguments);
-                } catch (Exception e) {
-                    CLog.w("Exception: " + e.getMessage());
-                }
-            }
-        }, TIMEOUT_SEC * 1000, device, inputFiles);
 
-        AdbUtils.assertNoCrashes(device, binaryName);
-        if (processPatternStrings != null) {
-            AdbUtils.assertNoCrashes(device, processPatternStrings);
-        }
-    }
+    /******************************************************************************
+     * To prevent merge conflicts, add tests for Q below this comment, before any
+     * existing test methods
+     ******************************************************************************/
 }
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMediaCodec.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMediaCodec.java
index d979183..734508b 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMediaCodec.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMediaCodec.java
@@ -26,9 +26,6 @@
 @SecurityTest
 public class TestMediaCodec extends SecurityTestCase {
 
-    final static int TIMEOUT_SEC = 9 * 60;
-    final static String RESOURCE_ROOT = "/";
-    final static String TMP_FILE_PATH = "/data/local/tmp/";
     final static String HEVCDEC_BINARY = "testhevc";
     final static String AVCDEC_BINARY = "testavc";
     final static String MPEG2DEC_BINARY = "testmpeg2";
@@ -39,177 +36,206 @@
     final static String AVCDEC_MEMUNDERFLOW_BINARY = "testavc_mem2";
     final static String MPEG2DEC_MEMUNDERFLOW_BINARY = "testmpeg2_mem2";
 
-    /***********************************************************
-    To prevent merge conflicts, add HEVC decoder tests for N
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add HEVC decoder tests for N below this comment,
+     * before any existing test methods
+     ******************************************************************************/
 
-    @SecurityTest
+    /**
+     * b/73965867
+     **/
+    @SecurityTest(minPatchLevel = "2018-06")
     public void testPocBug_73965867() throws Exception {
         String inputFiles[] = {"bug_73965867.hevc"};
-        runHevcDecodeTest(inputFiles,
-                "-i " + TMP_FILE_PATH + "bug_73965867.hevc", getDevice(), null);
+        runHevcDecodeTest(inputFiles, "-i " + AdbUtils.TMP_PATH + inputFiles[0], getDevice());
     }
 
-    @SecurityTest
+    /**
+     * b/64380202
+     **/
+    @SecurityTest(minPatchLevel = "2018-01")
     public void testPocBug_64380202() throws Exception {
         String inputFiles[] = {"bug_64380202.hevc"};
-        runHevcDecodeTest(inputFiles, "--input " + TMP_FILE_PATH
-                + "bug_64380202.hevc --num_frames -1 --num_cores 4",
-                getDevice(), null);
+        runHevcDecodeTest(inputFiles,
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --num_frames -1 --num_cores 4",
+                getDevice());
     }
 
-    @SecurityTest
+    /**
+     * b/64380403
+     **/
+    @SecurityTest(minPatchLevel = "2018-01")
     public void testPocBug_64380403() throws Exception {
         String inputFiles[] = {"bug_64380403.hevc"};
-        runHevcDecodeTest(inputFiles, "--input " + TMP_FILE_PATH
-                + "bug_64380403.hevc --num_frames -1 --num_cores 4",
-                getDevice(), null);
+        runHevcDecodeTest(inputFiles,
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --num_frames -1 --num_cores 4",
+                getDevice());
     }
 
-    /***********************************************************
-    To prevent merge conflicts, add HEVC decoder tests for O
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add HEVC decoder tests for O below this comment,
+     * before any existing test methods
+     ******************************************************************************/
+
+    /**
+     * b/68299873
+     **/
     @SecurityTest(minPatchLevel = "2018-01")
     public void testPocCVE_2017_13190() throws Exception {
-        runDecodeTest("CVE-2017-13190", null, null, getDevice(), null);
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2017-13190", null, null, AdbUtils.TMP_PATH,
+                getDevice());
     }
 
-
+    /**
+     * b/34897036
+     **/
     @SecurityTest(minPatchLevel = "2017-05")
     public void testPocCVE_2017_0589() throws Exception {
         String inputFiles[] = {"cve_2017_0589.hevc"};
-        runHevcDecodeMemTest(inputFiles,
-                "--input " + TMP_FILE_PATH + inputFiles[0] + " --save_output 0"
-                + " --num_frames -1", getDevice(), null);
+        runHevcDecodeMemTest(inputFiles, "--input " + AdbUtils.TMP_PATH + inputFiles[0]
+                + " --save_output 0" + " --num_frames -1", getDevice());
     }
 
+    /**
+     * b/65718319
+     **/
     @SecurityTest(minPatchLevel = "2018-01")
     public void testPocCVE_2017_13193() throws Exception {
         String inputFiles[] = {"cve_2017_13193.hevc"};
-        runHevcDecodeTest(inputFiles, "--input " + TMP_FILE_PATH
-                + "cve_2017_13193.hevc --num_frames -1", getDevice(), null);
+        runHevcDecodeTest(inputFiles,
+                "--input " + AdbUtils.TMP_PATH + "cve_2017_13193.hevc --num_frames -1",
+                getDevice());
     }
 
     @SecurityTest(minPatchLevel = "2017-07")
     public void testPocCVE_2017_0695() throws Exception {
         String inputFiles[] = {"cve_2017_0695.hevc"};
-        runHevcDecodeMemTest(inputFiles,
-                "--input " + TMP_FILE_PATH + inputFiles[0] + " --num_frames -1",
-                getDevice(), null);
+        runHevcDecodeTest(inputFiles,
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --num_frames -1",
+                getDevice());
     }
 
-    /***********************************************************
-    To prevent merge conflicts, add AVC decoder tests for N
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add AVC decoder tests for N below this comment,
+     * before any existing test methods
+     ******************************************************************************/
 
     @SecurityTest(minPatchLevel = "2017-03")
     public void testPocBug_33139050() throws Exception {
         String inputFiles[] = {"bug_33139050.h264"};
         runAvcDecodeMemTest(inputFiles,
-                "--input " + TMP_FILE_PATH
+                "--input " + AdbUtils.TMP_PATH
                         + "bug_33139050.h264 --output /dev/null --num_cores 2",
-                getDevice(), null);
+                getDevice());
     }
 
-    @SecurityTest
+    /**
+     * b/33621215
+     **/
+    @SecurityTest(minPatchLevel = "2017-03")
     public void testPocBug_33621215() throws Exception {
         String inputFiles[] = {"bug_33621215.h264"};
         runAvcDecodeTest(inputFiles,
-                "--input " + TMP_FILE_PATH
-                        + "bug_33621215.h264 --output /dev/null",
-                getDevice(), null);
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --output /dev/null",
+                getDevice());
     }
 
-    /***********************************************************
-    To prevent merge conflicts, add AVC decoder tests for O
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add AVC decoder tests for O below this comment,
+     * before any existing test methods
+     ******************************************************************************/
 
+    /**
+     * b/63521984
+     **/
     @SecurityTest(minPatchLevel = "2018-08")
     public void testPocCVE_2018_9444() throws Exception {
         String inputFiles[] = {"cve_2018_9444.h264"};
         runAvcDecodeTest(inputFiles,
-                "--input " + TMP_FILE_PATH + "cve_2018_9444.h264 --num_frames -1",
-                getDevice(), null);
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --num_frames -1", getDevice());
     }
 
-    /***********************************************************
-    To prevent merge conflicts, add MPEG2 decoder tests for N
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add MPEG2 decoder tests for N below this comment,
+     * before any existing test methods
+     ******************************************************************************/
 
-    @SecurityTest
+    /**
+     * b/34203195
+     **/
+    @SecurityTest(minPatchLevel = "2017-07")
     public void testPocBug_34203195() throws Exception {
         String inputFiles[] = {"bug_34203195.m2v"};
-        runMpeg2DecodeTest(inputFiles,
-                "--input " + TMP_FILE_PATH + "bug_34203195.m2v --num_cores 2 "
-                        + "--output /dev/null --num_frames -1",
-                getDevice(), null);
+        runMpeg2DecodeTest(inputFiles, "--input " + AdbUtils.TMP_PATH + inputFiles[0]
+                + " --num_cores 2 --output /dev/null --num_frames -1", getDevice());
     }
 
-    @SecurityTest
+    /**
+     * b/37561455
+     **/
+    @SecurityTest(minPatchLevel = "2017-08")
     public void testPocBug_37561455() throws Exception {
         String inputFiles[] = {"bug_37561455.m2v"};
-        runMpeg2DecodeTest(inputFiles,
-                "--input " + TMP_FILE_PATH
-                        + "bug_37561455.m2v --output /dev/null --num_frames -1",
-                getDevice(), null);
+        runMpeg2DecodeTest(inputFiles, "--input " + AdbUtils.TMP_PATH + inputFiles[0]
+                + " --output /dev/null --num_frames -1", getDevice());
     }
 
-    @SecurityTest
+    /**
+     * b/63316255
+     **/
+    @SecurityTest(minPatchLevel = "2017-12")
     public void testPocBug_63316255() throws Exception {
         String inputFiles[] = {"bug_63316255.m2v"};
         runMpeg2DecodeTest(inputFiles,
-                "--input " + TMP_FILE_PATH + "bug_63316255.m2v --num_frames -1",
-                getDevice(), null);
+                "--input " + AdbUtils.TMP_PATH + inputFiles[0] + " --num_frames -1", getDevice());
     }
 
-    /***********************************************************
-    To prevent merge conflicts, add MPEG2 decoder tests for O
-    below this comment, before any existing test methods
-    ***********************************************************/
+    /******************************************************************************
+     * To prevent merge conflicts, add MPEG2 decoder tests for O below this comment,
+     * before any existing test methods
+     ******************************************************************************/
 
 
     /**
-     * Calls runDecodeTest with HEVC decoder binary name as argument
+     * Calls runPocAssertNoCrashesNotVulnerable with HEVC decoder binary name as
+     * argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runHevcDecodeTest(String inputFiles[], String arguments,
-            ITestDevice device, String errPattern[]) throws Exception {
-        runDecodeTest(HEVCDEC_BINARY, inputFiles, arguments, device, errPattern);
+    public static void runHevcDecodeTest(String inputFiles[], String arguments, ITestDevice device)
+            throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(HEVCDEC_BINARY, arguments, inputFiles,
+                AdbUtils.TMP_PATH, device);
     }
 
     /**
-     * Calls runDecodeTest with MPEG2 decoder binary name as argument
+     * Calls runPocAssertNoCrashesNotVulnerable with MPEG2 decoder binary name as
+     * argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runMpeg2DecodeTest(String inputFiles[], String arguments,
-            ITestDevice device, String errPattern[]) throws Exception {
-        runDecodeTest(MPEG2DEC_BINARY, inputFiles, arguments, device, errPattern);
+    public static void runMpeg2DecodeTest(String inputFiles[], String arguments, ITestDevice device)
+            throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(MPEG2DEC_BINARY, arguments, inputFiles,
+                AdbUtils.TMP_PATH, device);
     }
 
     /**
-     * Calls runDecodeTest with AVC decoder binary name as argument
+     * Calls runPocAssertNoCrashesNotVulnerable with AVC decoder binary name as
+     * argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runAvcDecodeTest(String inputFiles[], String arguments,
-            ITestDevice device, String errPattern[]) throws Exception {
-        runDecodeTest(AVCDEC_BINARY, inputFiles, arguments, device, errPattern);
+    public static void runAvcDecodeTest(String inputFiles[], String arguments, ITestDevice device)
+            throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(AVCDEC_BINARY, arguments, inputFiles,
+                AdbUtils.TMP_PATH, device);
     }
 
     /**
@@ -218,44 +244,39 @@
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runHevcDecodeMemTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runHevcDecodeMemOverflowTest(inputFiles, arguments, device, errPattern);
-        runHevcDecodeMemUnderflowTest(inputFiles, arguments, device,
-                errPattern);
+    public static void runHevcDecodeMemTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        runHevcDecodeMemOverflowTest(inputFiles, arguments, device);
+        runHevcDecodeMemUnderflowTest(inputFiles, arguments, device);
     }
 
     /**
-     * Calls runDecodeTest with HEVC decoder overflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with HEVC decoder overflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runHevcDecodeMemOverflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(HEVCDEC_MEMOVERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
+    public static void runHevcDecodeMemOverflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(HEVCDEC_MEMOVERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 
     /**
-     * Calls runDecodeTest with HEVC decoder underflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with HEVC decoder underflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runHevcDecodeMemUnderflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(HEVCDEC_MEMUNDERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
+    public static void runHevcDecodeMemUnderflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(HEVCDEC_MEMUNDERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 
     /**
@@ -264,45 +285,39 @@
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runMpeg2DecodeMemTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runMpeg2DecodeMemOverflowTest(inputFiles, arguments, device,
-                errPattern);
-        runMpeg2DecodeMemUnderflowTest(inputFiles, arguments, device,
-                errPattern);
+    public static void runMpeg2DecodeMemTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        runMpeg2DecodeMemOverflowTest(inputFiles, arguments, device);
+        runMpeg2DecodeMemUnderflowTest(inputFiles, arguments, device);
     }
 
     /**
-     * Calls runDecodeTest with MPEG2 decoder overflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with MPEG2 decoder overflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runMpeg2DecodeMemOverflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(MPEG2DEC_MEMOVERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
+    public static void runMpeg2DecodeMemOverflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(MPEG2DEC_MEMOVERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 
     /**
-     * Calls runDecodeTest with MPEG2 decoder underflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with MPEG2 decoder underflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runMpeg2DecodeMemUnderflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(MPEG2DEC_MEMUNDERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
+    public static void runMpeg2DecodeMemUnderflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(MPEG2DEC_MEMUNDERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 
     /**
@@ -311,80 +326,38 @@
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runAvcDecodeMemTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runAvcDecodeMemOverflowTest(inputFiles, arguments, device, errPattern);
-        runAvcDecodeMemUnderflowTest(inputFiles, arguments, device, errPattern);
+    public static void runAvcDecodeMemTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        runAvcDecodeMemOverflowTest(inputFiles, arguments, device);
+        runAvcDecodeMemUnderflowTest(inputFiles, arguments, device);
     }
 
     /**
-     * Calls runDecodeTest with AVC decoder overflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with AVC decoder overflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runAvcDecodeMemOverflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(AVCDEC_MEMOVERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
+    public static void runAvcDecodeMemOverflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(AVCDEC_MEMOVERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 
     /**
-     * Calls runDecodeTest with AVC decoder underflow test binary name argument
+     * Calls runPocAssertNoCrashesNotVulnerable with AVC decoder underflow test
+     * binary name argument
      *
      * @param inputFiles files required as input
      * @param arguments arguments for running the binary
      * @param device device to be run on
-     * @param errPattern error patterns to be checked for
      */
-    public static void runAvcDecodeMemUnderflowTest(String inputFiles[],
-            String arguments, ITestDevice device, String errPattern[])
-            throws Exception {
-        runDecodeTest(AVCDEC_MEMUNDERFLOW_BINARY, inputFiles, arguments, device,
-                errPattern);
-    }
-
-
-    /**
-     * Pushes input files, runs the PoC and checks for crash and hang
-     *
-     * @param binaryName name of the decoder binary
-     * @param inputFiles files required as input
-     * @param arguments arguments for running the binary
-     * @param device device to be run on
-     * @param errPattern error patterns to be checked for
-     */
-    public static void runDecodeTest(String binaryName, String inputFiles[],
-            String arguments, ITestDevice device, String processPatternStrings[])
-            throws Exception {
-        if (inputFiles != null) {
-            for (int i = 0; i < inputFiles.length; i++) {
-                AdbUtils.pushResource(RESOURCE_ROOT + inputFiles[i],
-                        TMP_FILE_PATH + inputFiles[i], device);
-            }
-        }
-        AdbUtils.runCommandLine("logcat -c", device);
-        AdbUtils.runWithTimeoutDeleteFiles(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    AdbUtils.runPocNoOutput(binaryName, device,
-                            TIMEOUT_SEC + 30, arguments);
-                } catch (Exception e) {
-                    CLog.w("Exception: " + e.getMessage());
-                }
-            }
-        }, TIMEOUT_SEC * 1000, device, inputFiles);
-
-        AdbUtils.assertNoCrashes(device, binaryName);
-        if (processPatternStrings != null) {
-            AdbUtils.assertNoCrashes(device, processPatternStrings);
-        }
+    public static void runAvcDecodeMemUnderflowTest(String inputFiles[], String arguments,
+            ITestDevice device) throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable(AVCDEC_MEMUNDERFLOW_BINARY, arguments,
+                inputFiles, AdbUtils.TMP_PATH, device);
     }
 }