[compiler-rt] 15f26c5 - [dfsan] Wrap strcat
Jianzhou Zhao via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 10:51:03 PST 2021
Author: Jianzhou Zhao
Date: 2021-02-03T18:50:29Z
New Revision: 15f26c5f5191fd4cfdece0e9621efd395ba57bc8
URL: https://github.com/llvm/llvm-project/commit/15f26c5f5191fd4cfdece0e9621efd395ba57bc8
DIFF: https://github.com/llvm/llvm-project/commit/15f26c5f5191fd4cfdece0e9621efd395ba57bc8.diff
LOG: [dfsan] Wrap strcat
Reviewed-by: morehouse
Differential Revision: https://reviews.llvm.org/D95923
Added:
Modified:
compiler-rt/lib/dfsan/dfsan_custom.cpp
compiler-rt/lib/dfsan/done_abilist.txt
compiler-rt/test/dfsan/custom.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index f90c8e813340..e30e2a7cd918 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -353,6 +353,20 @@ void *__dfsw_memset(void *s, int c, size_t n,
return s;
}
+SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strcat(char *dest, const char *src,
+ dfsan_label dest_label,
+ dfsan_label src_label,
+ dfsan_label *ret_label) {
+ size_t dest_len = strlen(dest);
+ char *ret = strcat(dest, src);
+ dfsan_label *sdest = shadow_for(dest + dest_len);
+ const dfsan_label *ssrc = shadow_for(src);
+ internal_memcpy((void *)sdest, (const void *)ssrc,
+ strlen(src) * sizeof(dfsan_label));
+ *ret_label = dest_label;
+ return ret;
+}
+
SANITIZER_INTERFACE_ATTRIBUTE char *
__dfsw_strdup(const char *s, dfsan_label s_label, dfsan_label *ret_label) {
size_t len = strlen(s);
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 1ceabf1cba6c..c6297aa59de5 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -224,6 +224,7 @@ fun:strtol=custom
fun:strtoll=custom
fun:strtoul=custom
fun:strtoull=custom
+fun:strcat=custom
# Functions that produce an output that is computed from the input, but is not
# necessarily data dependent.
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 9129eff72bae..4676c91bed0f 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -155,6 +155,27 @@ void test_strcmp() {
#endif
}
+void test_strcat() {
+ char src[] = "world";
+ char dst[] = "hello \0 ";
+ char *p = dst;
+ dfsan_set_label(k_label, &p, sizeof(p));
+ dfsan_set_label(i_label, src, sizeof(src));
+ dfsan_set_label(j_label, dst, sizeof(dst));
+ char *ret = strcat(p, src);
+ ASSERT_LABEL(ret, k_label);
+ assert(ret == dst);
+ assert(strcmp(src, dst + 6) == 0);
+ for (int i = 0; i < 6; ++i) {
+ ASSERT_LABEL(dst[i], j_label);
+ }
+ for (int i = 6; i < strlen(dst); ++i) {
+ ASSERT_LABEL(dst[i], i_label);
+ assert(dfsan_get_label(dst[i]) == dfsan_get_label(src[i - 6]));
+ }
+ ASSERT_LABEL(dst[11], j_label);
+}
+
void test_strlen() {
char str1[] = "str1";
dfsan_set_label(i_label, &str1[3], 1);
@@ -1360,6 +1381,7 @@ int main(void) {
test_strcasecmp();
test_strchr();
test_strcmp();
+ test_strcat();
test_strcpy();
test_strdup();
test_strlen();
More information about the llvm-commits
mailing list