diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/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(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) { diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/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 diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp --- a/compiler-rt/test/dfsan/custom.cpp +++ b/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();