From 22aa1c3284730888acf60f732c10b25664b9240b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=87=91=E6=88=90?= Date: Sat, 7 Dec 2024 20:18:05 +0800 Subject: [PATCH] [Sanitizer] Add a flag to optionally skip the log_path check on iniliazition When initializing sanitizers, whether the log_path exists will be checked, and if not, it will attempt to create such a log_path to write the santizers' dignostic log. However, as santizers are preloaded when open an app, the sanitizers' checking for log_path during initialization happens before the mounting of each app's sandbox path. Consequently, during santiziers' initialization, the access or creation for log_path are denied, and subsequently the app crashes Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IB0NXJ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡金成 Change-Id: I3e8334bea8da28f797960883f41ff35d4f2c710b --- compiler-rt/lib/sanitizer_common/sanitizer_file.cpp | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_flags.inc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp index 6769d49ee129..0c7149c01c14 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp @@ -93,7 +93,7 @@ static void RecursiveCreateParentDirs(char *path) { if (!IsPathSeparator(path[i])) continue; path[i] = '\0'; - if (!DirExists(path) && !CreateDir(path)) { + if (common_flags()->check_log_path_on_init && !DirExists(path) && !CreateDir(path)) { // OHOS_LOCAL const char *ErrorMsgPrefix = "ERROR: Can't create directory: "; WriteToFile(kStderrFd, ErrorMsgPrefix, internal_strlen(ErrorMsgPrefix)); WriteToFile(kStderrFd, path, internal_strlen(path)); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc index 509bcf6afd1a..15a253feb116 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -19,6 +19,12 @@ // Default value must be a compile-time constant. // Description must be a string literal. +// OHOS_LOCAL begin +COMMON_FLAG( + bool, check_log_path_on_init, true, + "If set, log_path will be checked during initialization.") +// OHOS_LOCAL end + COMMON_FLAG( bool, symbolize, true, "If set, use the online symbolizer from common sanitizer runtime to turn " -- Gitee