forked from OSchip/llvm-project
[Sanitizer] Intercept sl_add api on FreeBSD/NetBSD
Reviewers: krytarowski, vitalybuka Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D56670 llvm-svn: 351189
This commit is contained in:
parent
cce1c2eb0e
commit
bd27e4c156
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
|
||||
// UNSUPPORTED: android
|
||||
|
||||
// UNSUPPORTED: android
|
||||
|
||||
|
|
|
@ -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 '{{.*}}'
|
||||
}
|
Loading…
Reference in New Issue