diff options
5 files changed, 36 insertions, 1 deletions
diff --git a/compiler-rt/lib/msan/lit_tests/setlocale.cc b/compiler-rt/lib/msan/lit_tests/setlocale.cc new file mode 100644 index 00000000000..a22b744d74d --- /dev/null +++ b/compiler-rt/lib/msan/lit_tests/setlocale.cc @@ -0,0 +1,13 @@ +// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t + +#include <assert.h> +#include <locale.h> +#include <stdlib.h> + +int main(void) { + char *locale = setlocale (LC_ALL, ""); + assert(locale); + if (locale[0]) + exit(0); + return 0; +} diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 6f76a4c2e7e..7d39e29311b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -1399,6 +1399,24 @@ INTERCEPTOR(uptr, ptrace, int request, int pid, void *addr, void *data) { #define INIT_PTRACE #endif +#if SANITIZER_INTERCEPT_SETLOCALE +INTERCEPTOR(char *, setlocale, int category, char *locale) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, setlocale, category, locale); + if (locale) + COMMON_INTERCEPTOR_READ_RANGE(ctx, locale, REAL(strlen)(locale) + 1); + char * res = REAL(setlocale)(category, locale); + if (res) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1); + return res; +} + +#define INIT_SETLOCALE \ + INTERCEPT_FUNCTION(setlocale); +#else +#define INIT_SETLOCALE +#endif + #define SANITIZER_COMMON_INTERCEPTORS_INIT \ INIT_STRCASECMP; \ @@ -1445,4 +1463,5 @@ INTERCEPTOR(uptr, ptrace, int request, int pid, void *addr, void *data) { INIT_SYSINFO; \ INIT_READDIR; \ INIT_READDIR64; \ - INIT_PTRACE; + INIT_PTRACE; \ + INIT_SETLOCALE; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 7ddde75fdf4..b749a625093 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -96,5 +96,6 @@ # define SANITIZER_INTERCEPT_READDIR SI_NOT_WINDOWS # define SANITIZER_INTERCEPT_READDIR64 SI_LINUX_NOT_ANDROID # define SANITIZER_INTERCEPT_PTRACE SI_LINUX_NOT_ANDROID +# define SANITIZER_INTERCEPT_SETLOCALE SI_NOT_WINDOWS #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc index f2925cb53a0..01ca2d38a3a 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc @@ -337,6 +337,7 @@ void StatOutput(u64 *stat) { name[StatInt_readdir_r] = " readdir_r "; name[StatInt_readdir64_r] = " readdir64_r "; name[StatInt_ptrace] = " ptrace "; + name[StatInt_setlocale] = " setlocale "; name[StatAnnotation] = "Dynamic annotations "; name[StatAnnotateHappensBefore] = " HappensBefore "; diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h index cd832168f4d..a67e457b208 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.h +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h @@ -332,6 +332,7 @@ enum StatType { StatInt_readdir_r, StatInt_readdir64_r, StatInt_ptrace, + StatInt_setlocale, // Dynamic annotations. StatAnnotation, |

