summaryrefslogtreecommitdiff
path: root/test/sanitizer_common
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-02-01 23:34:30 +0000
committerKamil Rytarowski <n54@gmx.com>2018-02-01 23:34:30 +0000
commit5197e945a56dd5da7925c64b06f9ca14a7385786 (patch)
tree03e930138d362dd8049f07e9f75d225a4d498fce /test/sanitizer_common
parent06fb62d8d28bdf6a7590a47a6b14a65473c823a8 (diff)
Add new interceptors: strlcpy(3) and strlcat(3)
Summary: NetBSD ships with strlcpy(3) and strlcat(3), a safe replacement of strcpy(3) and strcat(3). Hide both functions under SANITIZER_INTERCEPT_STRLCPY. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka Reviewed By: vitalybuka Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D42061 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@324034 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/sanitizer_common')
-rw-r--r--test/sanitizer_common/TestCases/NetBSD/strlcat.cc52
-rw-r--r--test/sanitizer_common/TestCases/NetBSD/strlcpy.cc52
2 files changed, 104 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/NetBSD/strlcat.cc b/test/sanitizer_common/TestCases/NetBSD/strlcat.cc
new file mode 100644
index 000000000..ea504589e
--- /dev/null
+++ b/test/sanitizer_common/TestCases/NetBSD/strlcat.cc
@@ -0,0 +1,52 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1() {
+ const char src[] = "abc";
+ char dst[7] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test2() {
+ const char src[] = "abc";
+ char dst[7] = {0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test3() {
+ const char src[] = "abc";
+ char dst[4] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test4() {
+ const char src[] = "";
+ char dst[4] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu\n", dst, len);
+}
+
+int main(void) {
+ test1();
+ test2();
+ test3();
+ test4();
+
+ // CHECK: xyzabc 6 abc 3 xyz 3 xyz 3
+
+ return 0;
+}
diff --git a/test/sanitizer_common/TestCases/NetBSD/strlcpy.cc b/test/sanitizer_common/TestCases/NetBSD/strlcpy.cc
new file mode 100644
index 000000000..996348602
--- /dev/null
+++ b/test/sanitizer_common/TestCases/NetBSD/strlcpy.cc
@@ -0,0 +1,52 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1() {
+ const char src[] = "abc";
+ char dst[7] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcpy(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test2() {
+ const char src[] = "abc";
+ char dst[7] = {0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test3() {
+ const char src[] = "abc";
+ char dst[4] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu ", dst, len);
+}
+
+void test4() {
+ const char src[] = "";
+ char dst[4] = {'x', 'y', 'z', 0};
+ size_t len;
+
+ len = strlcat(dst, src, sizeof(dst));
+ printf("%s %zu\n", dst, len);
+}
+
+int main(void) {
+ test1();
+ test2();
+ test3();
+ test4();
+
+ // CHECK: abc 3 abc 3 xyz 3 0
+
+ return 0;
+}