[compiler-rt] [HWASAN] Add test to detected use after free in memcmp (PR #67204)

Kirill Stoimenov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 16:02:40 PDT 2023


https://github.com/kstoimenov created https://github.com/llvm/llvm-project/pull/67204

The plan is to fix memcmp interceptor in HWASAN and remove the unsupported statement at that time. 

>From 3483b52cfaec660a0acc577679d0f4ce3e7e7eef Mon Sep 17 00:00:00 2001
From: Kirill Stoimenov <kstoimenov at google.com>
Date: Fri, 22 Sep 2023 22:57:55 +0000
Subject: [PATCH] [HWASAN] Add test to detected use after free in memcmp

---
 .../test/sanitizer_common/TestCases/memcmp.cpp    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 compiler-rt/test/sanitizer_common/TestCases/memcmp.cpp

diff --git a/compiler-rt/test/sanitizer_common/TestCases/memcmp.cpp b/compiler-rt/test/sanitizer_common/TestCases/memcmp.cpp
new file mode 100644
index 000000000000000..23fe8e2cfe0d620
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/memcmp.cpp
@@ -0,0 +1,15 @@
+// RUN: %clangxx -O0 %s -o %t && %run %t
+// XFAIL: *
+// UNSUPPORTED: lsan, ubsan
+// FIXME: HWASAN should work when we have intercepptors.
+// UNSUPPORTED: hwasan
+
+#include <cstring>
+#include <cstdio>
+
+int main(int argc, char** argv) {
+  int *x = new int(7);
+  delete x;
+  // Trigger use after free error.
+  return memcmp(x, &argc, sizeof(int)) == 0 ? 1 : 0;
+}
\ No newline at end of file



More information about the llvm-commits mailing list