diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-31 01:17:41 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-31 01:17:41 +0000 |
commit | 26fe5d396c5c99ddcd89b3f8722cea1d4940b9e9 (patch) | |
tree | 1400bfa274ed1531028022eda26e0d20380c4c02 /lib/sanitizer_common | |
parent | 6f5427b0ebc5ced4497f8ef00bd19fc0bd6c33b7 (diff) | |
download | compiler-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
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_interceptors.inc | 32 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform_interceptors.h | 3 |
2 files changed, 35 insertions, 0 deletions
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 |