[compiler-rt] bf281f3 - [dfsan] Add wrappers for v*printf functions
George Balatsouras via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 22 15:39:28 PDT 2021
Author: George Balatsouras
Date: 2021-07-22T15:39:17-07:00
New Revision: bf281f364757d6af8d9d8456f26d334d1eeaf575
URL: https://github.com/llvm/llvm-project/commit/bf281f364757d6af8d9d8456f26d334d1eeaf575
DIFF: https://github.com/llvm/llvm-project/commit/bf281f364757d6af8d9d8456f26d334d1eeaf575.diff
LOG: [dfsan] Add wrappers for v*printf functions
Functions `vsnprintf`, `vsprintf` and `vfprintf` commonly occur in DFSan warnings.
Reviewed By: stephan.yichao.zhao
Differential Revision: https://reviews.llvm.org/D106195
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 3185184f29c8..edc07547ef32 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -2460,6 +2460,49 @@ int __dfso_snprintf(char *str, size_t size, const char *format,
return ret;
}
+SANITIZER_INTERFACE_ATTRIBUTE
+int __dfsw_vsprintf(char *str, const char *format, dfsan_label str_label,
+ dfsan_label format_label, dfsan_label *va_labels,
+ dfsan_label *ret_label, va_list ap) {
+ int ret = format_buffer(str, ~0ul, format, va_labels, ret_label, nullptr,
+ nullptr, ap);
+ return ret;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE
+int __dfso_vsprintf(char *str, const char *format, dfsan_label str_label,
+ dfsan_label format_label, dfsan_label *va_labels,
+ dfsan_label *ret_label, dfsan_origin str_origin,
+ dfsan_origin format_origin, dfsan_origin *va_origins,
+ dfsan_origin *ret_origin, va_list ap) {
+ int ret = format_buffer(str, ~0ul, format, va_labels, ret_label, va_origins,
+ ret_origin, ap);
+ return ret;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE
+int __dfsw_vsnprintf(char *str, size_t size, const char *format,
+ dfsan_label str_label, dfsan_label size_label,
+ dfsan_label format_label, dfsan_label *va_labels,
+ dfsan_label *ret_label, va_list ap) {
+ int ret = format_buffer(str, size, format, va_labels, ret_label, nullptr,
+ nullptr, ap);
+ return ret;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE
+int __dfso_vsnprintf(char *str, size_t size, const char *format,
+ dfsan_label str_label, dfsan_label size_label,
+ dfsan_label format_label, dfsan_label *va_labels,
+ dfsan_label *ret_label, dfsan_origin str_origin,
+ dfsan_origin size_origin, dfsan_origin format_origin,
+ dfsan_origin *va_origins, dfsan_origin *ret_origin,
+ va_list ap) {
+ int ret = format_buffer(str, size, format, va_labels, ret_label, va_origins,
+ ret_origin, ap);
+ return ret;
+}
+
static void BeforeFork() {
StackDepotLockAll();
GetChainedOriginDepot()->LockAll();
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 111c7d581e0a..4e4466e4eeb0 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -206,6 +206,7 @@ fun:symlink=discard
fun:syscall=discard
fun:unlink=discard
fun:uselocale=discard
+fun:vfprintf=discard
# Functions that produce output does not depend on the input (need to zero the
# shadow manually).
@@ -285,6 +286,8 @@ fun:gettimeofday=custom
# sprintf-like
fun:sprintf=custom
fun:snprintf=custom
+fun:vsprintf=custom
+fun:vsnprintf=custom
# TODO: custom
fun:asprintf=discard
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 99450a6c1e71..8d1ef49e034d 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -1939,6 +1939,14 @@ void test_snprintf() {
ASSERT_LABEL(r, 0);
}
+// This is essentially the same as sprintf with the only
diff erence that it
+// uses a va_list instead of varargs. This empty function is here to appease
+// the check-wrappers script.
+void test_vsprintf() {}
+
+// Same here, but for snprintf.
+void test_vsnprintf() {}
+
// Tested by a seperate source file. This empty function is here to appease the
// check-wrappers script.
void test_fork() {}
@@ -2019,5 +2027,7 @@ int main(void) {
test_strtoul();
test_strtoull();
test_time();
+ test_vsprintf();
+ test_vsnprintf();
test_write();
}
More information about the llvm-commits
mailing list