summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-31 01:17:41 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-31 01:17:41 +0000
commit26fe5d396c5c99ddcd89b3f8722cea1d4940b9e9 (patch)
tree1400bfa274ed1531028022eda26e0d20380c4c02
parent6f5427b0ebc5ced4497f8ef00bd19fc0bd6c33b7 (diff)
downloadcompiler-rt-26fe5d396c5c99ddcd89b3f8722cea1d4940b9e9.tar.gz
compiler-rt-26fe5d396c5c99ddcd89b3f8722cea1d4940b9e9.tar.bz2
compiler-rt-26fe5d396c5c99ddcd89b3f8722cea1d4940b9e9.tar.xz
[sanitizer] Intercept getline, getdelim.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193730 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/msan/lit_tests/getline.cc30
-rw-r--r--lib/msan/lit_tests/getline_test_data2
-rw-r--r--lib/sanitizer_common/sanitizer_common_interceptors.inc32
-rw-r--r--lib/sanitizer_common/sanitizer_platform_interceptors.h3
-rw-r--r--lib/tsan/rtl/tsan_stat.cc2
-rw-r--r--lib/tsan/rtl/tsan_stat.h2
6 files changed, 71 insertions, 0 deletions
diff --git a/lib/msan/lit_tests/getline.cc b/lib/msan/lit_tests/getline.cc
new file mode 100644
index 00000000..27168a88
--- /dev/null
+++ b/lib/msan/lit_tests/getline.cc
@@ -0,0 +1,30 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %t %p
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ assert(argc == 2);
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "%s/%s", argv[1], "getline_test_data");
+
+ FILE *fp = fopen(buf, "r");
+ assert(fp);
+
+ char *line = 0;
+ size_t len = 0;
+ int n = getline(&line, &len, fp);
+ assert(n == 6);
+ assert(strcmp(line, "abcde\n") == 0);
+
+ n = getline(&line, &len, fp);
+ assert(n == 6);
+ assert(strcmp(line, "12345\n") == 0);
+
+ free(line);
+ fclose(fp);
+
+ return 0;
+}
diff --git a/lib/msan/lit_tests/getline_test_data b/lib/msan/lit_tests/getline_test_data
new file mode 100644
index 00000000..5ba1d4ce
--- /dev/null
+++ b/lib/msan/lit_tests/getline_test_data
@@ -0,0 +1,2 @@
+abcde
+12345
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 7c8669a2..3e716a7c 100644
--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2811,6 +2811,37 @@ INTERCEPTOR(int, lrand48_r, void *buffer, long *result) {
#define INIT_DRAND48_R
#endif
+#if SANITIZER_INTERCEPT_GETLINE
+INTERCEPTOR(SSIZE_T, getline, char **lineptr, SIZE_T *n, void *stream) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getline, lineptr, n, stream);
+ SSIZE_T res = REAL(getline)(lineptr, n, stream);
+ if (res > 0) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lineptr, sizeof(*lineptr));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n, sizeof(*n));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *lineptr, res + 1);
+ }
+ return res;
+}
+INTERCEPTOR(SSIZE_T, getdelim, char **lineptr, SIZE_T *n, int delim,
+ void *stream) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getdelim, lineptr, n, delim, stream);
+ SSIZE_T res = REAL(getdelim)(lineptr, n, delim, stream);
+ if (res > 0) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lineptr, sizeof(*lineptr));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n, sizeof(*n));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *lineptr, res + 1);
+ }
+ return res;
+}
+#define INIT_GETLINE \
+ INTERCEPT_FUNCTION(getline); \
+ INTERCEPT_FUNCTION(getdelim);
+#else
+#define INIT_GETLINE
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCMP; \
INIT_STRNCMP; \
@@ -2918,4 +2949,5 @@ INTERCEPTOR(int, lrand48_r, void *buffer, long *result) {
INIT_LGAMMA; \
INIT_LGAMMA_R; \
INIT_DRAND48_R; \
+ INIT_GETLINE; \
/**/
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 3346be01..f9a9870c 100644
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -150,6 +150,9 @@
# define SANITIZER_INTERCEPT_LGAMMA_R SI_LINUX
# define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID
+// FIXME: getline seems to be available on OSX 10.7
+# define SANITIZER_INTERCEPT_GETLINE SI_LINUX_NOT_ANDROID
+
# define SANITIZER_INTERCEPT__EXIT SI_LINUX
# define SANITIZER_INTERCEPT_PHTREAD_MUTEX SI_NOT_WINDOWS
diff --git a/lib/tsan/rtl/tsan_stat.cc b/lib/tsan/rtl/tsan_stat.cc
index 6082120f..72d173de 100644
--- a/lib/tsan/rtl/tsan_stat.cc
+++ b/lib/tsan/rtl/tsan_stat.cc
@@ -412,6 +412,8 @@ void StatOutput(u64 *stat) {
name[StatInt_lgammal_r] = " lgammal_r ";
name[StatInt_drand48_r] = " drand48_r ";
name[StatInt_lrand48_r] = " lrand48_r ";
+ name[StatInt_getline] = " getline ";
+ name[StatInt_getdelim] = " getdelim ";
name[StatInt_pthread_attr_getdetachstate] = " pthread_addr_getdetachstate "; // NOLINT
name[StatInt_pthread_attr_getguardsize] = " pthread_addr_getguardsize "; // NOLINT
diff --git a/lib/tsan/rtl/tsan_stat.h b/lib/tsan/rtl/tsan_stat.h
index 4d0ec3fc..d6ff93c5 100644
--- a/lib/tsan/rtl/tsan_stat.h
+++ b/lib/tsan/rtl/tsan_stat.h
@@ -407,6 +407,8 @@ enum StatType {
StatInt_lgammal_r,
StatInt_drand48_r,
StatInt_lrand48_r,
+ StatInt_getline,
+ StatInt_getdelim,
StatInt_pthread_attr_getdetachstate,
StatInt_pthread_attr_getguardsize,