diff options
author | David Carlier <devnexen@gmail.com> | 2019-01-15 11:21:33 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2019-01-15 11:21:33 +0000 |
commit | 8d4ad462c174450218de6b69bc2fb61a25e76922 (patch) | |
tree | cda9b1a896437f2cc2fc87aebaad11c2e2cc6d91 | |
parent | 78bf4c485c974b74d4a8770088e08eaf9377cfb9 (diff) |
[Sanitizer] Intercept sl_add api on FreeBSD/NetBSDlinaro-local/ci/tcwg_kernel/llvm-master-aarch64-mainline-allyesconfig
Reviewers: krytarowski, vitalybuka
Reviewed By: krytarowski
Differential Revision: https://reviews.llvm.org/D56670
8 files changed, 92 insertions, 5 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index f3ea863bdf4..50f7837747e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -9414,6 +9414,59 @@ INTERCEPTOR(char *, getusershell) { #define INIT_GETUSERSHELL #endif +#if SANITIZER_INTERCEPT_SL_INIT +INTERCEPTOR(void *, sl_init) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, sl_init); + void *res = REAL(sl_init)(); + if (res) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, __sanitizer::struct_StringList_sz); + return res; +} + +INTERCEPTOR(int, sl_add, void *sl, char *item) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, sl_add, sl, item); + if (sl) + COMMON_INTERCEPTOR_READ_RANGE(ctx, sl, __sanitizer::struct_StringList_sz); + if (item) + COMMON_INTERCEPTOR_READ_RANGE(ctx, item, REAL(strlen)(item) + 1); + int res = REAL(sl_add)(sl, item); + if (!res) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, sl, __sanitizer::struct_StringList_sz); + return res; +} + +INTERCEPTOR(char *, sl_find, void *sl, const char *item) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, sl_find, sl, item); + if (sl) + COMMON_INTERCEPTOR_READ_RANGE(ctx, sl, __sanitizer::struct_StringList_sz); + if (item) + COMMON_INTERCEPTOR_READ_RANGE(ctx, item, REAL(strlen)(item) + 1); + char *res = REAL(sl_find)(sl, item); + if (res) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1); + return res; +} + +INTERCEPTOR(void, sl_free, void *sl, int freeall) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, sl_free, sl, freeall); + if (sl) + COMMON_INTERCEPTOR_READ_RANGE(ctx, sl, __sanitizer::struct_StringList_sz); + REAL(sl_free)(sl, freeall); +} + +#define INIT_SL_INIT \ + COMMON_INTERCEPT_FUNCTION(sl_init); \ + COMMON_INTERCEPT_FUNCTION(sl_add); \ + COMMON_INTERCEPT_FUNCTION(sl_find); \ + COMMON_INTERCEPT_FUNCTION(sl_free); +#else +#define INIT_SL_INIT +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = @@ -9703,6 +9756,7 @@ static void InitializeCommonInterceptors() { INIT_FUNOPEN2; INIT_FDEVNAME; INIT_GETUSERSHELL; + INIT_SL_INIT; INIT___PRINTF_CHK; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index bf5f4ae0ed9..4d146651b78 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -545,15 +545,15 @@ #define SANITIZER_INTERCEPT_SHA2 SI_NETBSD #define SANITIZER_INTERCEPT_CDB SI_NETBSD #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD) -#define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC) -#define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD) -#define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD -#define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_POSIX) - #define SANITIZER_INTERCEPT_POPEN SI_POSIX #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX #define SANITIZER_INTERCEPT_FUNOPEN (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD +#define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC) +#define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD) +#define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD +#define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_POSIX) +#define SANITIZER_INTERCEPT_SL_INIT (SI_FREEBSD || SI_NETBSD) #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc index f28fff15ed0..377a62cab6c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc @@ -65,6 +65,7 @@ #include <net/ppp_defs.h> #include <glob.h> #include <stdio.h> +#include <stringlist.h> #include <term.h> #include <utmpx.h> #include <wchar.h> @@ -133,6 +134,7 @@ namespace __sanitizer { unsigned struct_fstab_sz = sizeof(struct fstab); unsigned struct_FTS_sz = sizeof(FTS); unsigned struct_FTSENT_sz = sizeof(FTSENT); + unsigned struct_StringList_sz = sizeof(StringList); const uptr sig_ign = (uptr)SIG_IGN; const uptr sig_dfl = (uptr)SIG_DFL; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h index 97e92e4df52..588bead2ac1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h @@ -630,6 +630,7 @@ namespace __sanitizer { extern unsigned struct_cap_rights_sz; extern unsigned struct_fstab_sz; + extern unsigned struct_StringList_sz; } // namespace __sanitizer #define CHECK_TYPE_SIZE(TYPE) \ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc index 419815b0d8d..b23b430d9e5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc @@ -220,6 +220,7 @@ #include <fts.h> #include <regex.h> #include <fstab.h> +#include <stringlist.h> // clang-format on // Include these after system headers to avoid name clashes and ambiguities. @@ -831,6 +832,7 @@ unsigned struct_RF_ComponentLabel_sz = sizeof(RF_ComponentLabel_t); unsigned struct_RF_SingleComponent_sz = sizeof(RF_SingleComponent_t); unsigned struct_RF_ProgressInfo_sz = sizeof(RF_ProgressInfo_t); unsigned struct_nvlist_ref_sz = sizeof(struct __sanitizer_nvlist_ref_t); +unsigned struct_StringList_sz = sizeof(StringList); const unsigned IOCTL_NOT_PRESENT = 0; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h index 8cd8e43da6a..0c0c8a837b8 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h @@ -989,6 +989,7 @@ extern unsigned struct_RF_ComponentLabel_sz; extern unsigned struct_RF_SingleComponent_sz; extern unsigned struct_RF_ProgressInfo_sz; extern unsigned struct_nvlist_ref_sz; +extern unsigned struct_StringList_sz; // A special value to mark ioctls that are not present on the target platform, diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc index c00d75f1121..42ee03fffc0 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc @@ -1,4 +1,5 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// UNSUPPORTED: android // UNSUPPORTED: android diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/sl_add.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/sl_add.cc new file mode 100644 index 00000000000..4da70c7888f --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/sl_add.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <stringlist.h> + +int main(void) { + printf("sl_add\n"); + + StringList *sl = sl_init(); + assert(sl); + char *p = strdup("entry"); + assert(!sl_add(sl, p)); + char *entry = sl_find(sl, "entry"); + assert(!strcmp(entry, p)); + printf("Found '%s'\n", entry); + sl_free(sl, 1); + + return 0; + // CHECK: sl_add + // CHECK: Found '{{.*}}' +} |