[PATCH] D87849: [DFSan] Add strpbrk wrapper.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 12:22:49 PDT 2020


morehouse created this revision.
morehouse added a reviewer: vitalybuka.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.
morehouse requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87849

Files:
  compiler-rt/lib/dfsan/dfsan_custom.cpp
  compiler-rt/lib/dfsan/done_abilist.txt
  compiler-rt/test/dfsan/custom.cpp


Index: compiler-rt/test/dfsan/custom.cpp
===================================================================
--- compiler-rt/test/dfsan/custom.cpp
+++ compiler-rt/test/dfsan/custom.cpp
@@ -758,6 +758,40 @@
 #endif
 }
 
+void test_strpbrk() {
+  char s[] = "abcdefg";
+  char accept[] = "123fd";
+  dfsan_set_label(i_label, &s[5], 1);
+  dfsan_set_label(j_label, &accept[1], 1);
+
+  char *rv = strpbrk(s, accept);
+  assert(rv == &s[3]);
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_ZERO_LABEL(rv);
+#else
+  ASSERT_LABEL(rv, j_label);
+#endif
+
+  char *ps = s;
+  dfsan_set_label(j_label, &ps, sizeof(ps));
+
+  rv = strpbrk(ps, "123gf");
+  assert(rv == &s[5]);
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_LABEL(rv, j_label);
+#else
+  ASSERT_LABEL(rv, i_j_label);
+#endif
+
+  rv = strpbrk(ps, "123");
+  assert(rv == NULL);
+#ifdef STRICT_DATA_DEPENDENCIES
+  ASSERT_ZERO_LABEL(rv);
+#else
+  ASSERT_LABEL(rv, i_j_label);
+#endif
+}
+
 void test_memchr() {
   char str1[] = "str1";
   dfsan_set_label(i_label, &str1[3], 1);
@@ -1030,6 +1064,7 @@
   test_strncasecmp();
   test_strncmp();
   test_strncpy();
+  test_strpbrk();
   test_strrchr();
   test_strstr();
   test_strtod();
Index: compiler-rt/lib/dfsan/done_abilist.txt
===================================================================
--- compiler-rt/lib/dfsan/done_abilist.txt
+++ compiler-rt/lib/dfsan/done_abilist.txt
@@ -192,6 +192,7 @@
 fun:strlen=custom
 fun:strncasecmp=custom
 fun:strncmp=custom
+fun:strpbrk=custom
 fun:strrchr=custom
 fun:strstr=custom
 
Index: compiler-rt/lib/dfsan/dfsan_custom.cpp
===================================================================
--- compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -95,6 +95,24 @@
   }
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strpbrk(const char *s,
+                                                   const char *accept,
+                                                   dfsan_label s_label,
+                                                   dfsan_label accept_label,
+                                                   dfsan_label *ret_label) {
+  const char *ret = strpbrk(s, accept);
+  if (flags().strict_data_dependencies) {
+    *ret_label = ret ? s_label : 0;
+  } else {
+    size_t s_bytes_read = ret ? ret - s + 1 : strlen(s) + 1;
+    *ret_label =
+        dfsan_union(dfsan_read_label(s, s_bytes_read),
+                    dfsan_union(dfsan_read_label(accept, strlen(accept) + 1),
+                                dfsan_union(s_label, accept_label)));
+  }
+  return const_cast<char *>(ret);
+}
+
 static int dfsan_memcmp_bcmp(const void *s1, const void *s2, size_t n,
                              dfsan_label s1_label, dfsan_label s2_label,
                              dfsan_label n_label, dfsan_label *ret_label) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87849.292587.patch
Type: text/x-patch
Size: 2811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200917/7a4df8cc/attachment.bin>


More information about the llvm-commits mailing list