[compiler-rt] r300924 - sanitizer: fix crash with textdomain(NULL) interceptor

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 20 16:38:10 PDT 2017


Author: kcc
Date: Thu Apr 20 18:38:10 2017
New Revision: 300924

URL: http://llvm.org/viewvc/llvm-project?rev=300924&view=rev
Log:
sanitizer: fix crash with textdomain(NULL) interceptor

Summary:
The textdomain function accepts a NULL parameter (and should then return the
current message domain). Add a check for this and include ASAN tests.

Link: https://github.com/google/sanitizers/issues/787

Reviewers: m.guseva, kcc

Reviewed By: kcc

Subscribers: kubamracek

Differential Revision: https://reviews.llvm.org/D32318

Added:
    compiler-rt/trunk/test/asan/TestCases/textdomain.c
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=300924&r1=300923&r2=300924&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Apr 20 18:38:10 2017
@@ -304,7 +304,7 @@ INTERCEPTOR(SIZE_T, strnlen, const char
 INTERCEPTOR(char*, textdomain, const char *domainname) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, textdomain, domainname);
-  COMMON_INTERCEPTOR_READ_STRING(ctx, domainname, 0);
+  if (domainname) COMMON_INTERCEPTOR_READ_STRING(ctx, domainname, 0);
   char *domain = REAL(textdomain)(domainname);
   if (domain) {
     COMMON_INTERCEPTOR_INITIALIZE_RANGE(domain, REAL(strlen)(domain) + 1);

Added: compiler-rt/trunk/test/asan/TestCases/textdomain.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/textdomain.c?rev=300924&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/textdomain.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/textdomain.c Thu Apr 20 18:38:10 2017
@@ -0,0 +1,10 @@
+// RUN: %clang_asan -O0 -g %s -o %t
+// RUN: %env_asan_opts=strict_string_checks=1 %run %t
+
+#include <stdlib.h>
+#include <libintl.h>
+
+int main() {
+  textdomain(NULL);
+  return 0;
+}




More information about the llvm-commits mailing list