From: David Carlier Date: Sat, 22 Dec 2018 11:17:27 +0000 (+0000) Subject: [Sanitizer] Enable POSIX regex api on FreeBSD. X-Git-Tag: llvmorg-8.0.0-rc1~1327 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58d38230867528b2cc376a99c2147c89c7af6fcb;p=platform%2Fupstream%2Fllvm.git [Sanitizer] Enable POSIX regex api on FreeBSD. Reviewers: krytarowski Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D56009 M lib/sanitizer_common/sanitizer_common_interceptors.inc M lib/sanitizer_common/sanitizer_platform_interceptors.h M lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc M lib/sanitizer_common/sanitizer_platform_limits_freebsd.h D test/sanitizer_common/TestCases/NetBSD/regex.cc A + test/sanitizer_common/TestCases/Posix/regex.cc llvm-svn: 350002 --- diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index ff378e1..1f446fe 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7421,6 +7421,16 @@ INTERCEPTOR(void, regfree, const void *preg) { COMMON_INTERCEPTOR_READ_RANGE(ctx, preg, struct_regex_sz); REAL(regfree)(preg); } +#define INIT_REGEX \ + COMMON_INTERCEPT_FUNCTION(regcomp); \ + COMMON_INTERCEPT_FUNCTION(regexec); \ + COMMON_INTERCEPT_FUNCTION(regerror); \ + COMMON_INTERCEPT_FUNCTION(regfree); +#else +#define INIT_REGEX +#endif + +#if SANITIZER_INTERCEPT_REGEXSUB INTERCEPTOR(SSIZE_T, regnsub, char *buf, SIZE_T bufsiz, const char *sub, const struct __sanitizer_regmatch *rm, const char *str) { void *ctx; @@ -7455,15 +7465,12 @@ INTERCEPTOR(SSIZE_T, regasub, char **buf, const char *sub, } return res; } -#define INIT_REGEX \ - COMMON_INTERCEPT_FUNCTION(regcomp); \ - COMMON_INTERCEPT_FUNCTION(regexec); \ - COMMON_INTERCEPT_FUNCTION(regerror); \ - COMMON_INTERCEPT_FUNCTION(regfree); \ + +#define INIT_REGEXSUB \ COMMON_INTERCEPT_FUNCTION(regnsub); \ COMMON_INTERCEPT_FUNCTION(regasub); #else -#define INIT_REGEX +#define INIT_REGEXSUB #endif #if SANITIZER_INTERCEPT_FTS @@ -9297,6 +9304,7 @@ static void InitializeCommonInterceptors() { INIT_SETVBUF; INIT_GETVFSSTAT; INIT_REGEX; + INIT_REGEXSUB; INIT_FTS; INIT_SYSCTL; INIT_ASYSCTL; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index a914d20..f3a3207 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -522,7 +522,8 @@ #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC) #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD -#define SANITIZER_INTERCEPT_REGEX SI_NETBSD +#define SANITIZER_INTERCEPT_REGEX (SI_NETBSD || SI_FREEBSD) +#define SANITIZER_INTERCEPT_REGEXSUB SI_NETBSD #define SANITIZER_INTERCEPT_FTS SI_NETBSD #define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD || SI_MAC) #define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD 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 3eaa695..8bca8f4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,8 @@ namespace __sanitizer { unsigned struct_statvfs_sz = sizeof(struct statvfs); unsigned struct_shminfo_sz = sizeof(struct shminfo); unsigned struct_shm_info_sz = sizeof(struct shm_info); + unsigned struct_regmatch_sz = sizeof(regmatch_t); + unsigned struct_regex_sz = sizeof(regex_t); 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 b212c00..d383bce 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h @@ -62,6 +62,8 @@ namespace __sanitizer { extern unsigned struct_rlimit_sz; extern unsigned struct_utimbuf_sz; extern unsigned struct_timespec_sz; + extern unsigned struct_regmatch_sz; + extern unsigned struct_regex_sz; extern const int unvis_valid; extern const int unvis_validpush; diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc similarity index 62% rename from compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc rename to compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc index 8a4fb38..a6f19f3 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/regex.cc +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cc @@ -1,10 +1,16 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris #include #include #include #include +#ifndef __arraycount +#define __arraycount(a) ((sizeof(a) / sizeof(a[0]))) +#endif + void test_matched(const regex_t *preg, const char *string) { int rv = regexec(preg, string, 0, NULL, 0); if (!rv) @@ -33,37 +39,6 @@ void test_print_matches(const regex_t *preg, const char *string) { abort(); } -void test_nsub(const regex_t *preg, const char *string) { - regmatch_t rm[10]; - int rv = regexec(preg, string, __arraycount(rm), rm, 0); - if (!rv) { - char buf[1024]; - ssize_t ss = regnsub(buf, __arraycount(buf), "\\1xyz", rm, string); - assert(ss != -1); - - printf("'%s' -> '%s'\n", string, buf); - } else if (rv == REG_NOMATCH) - printf("%s: not-matched\n", string); - else - abort(); -} - -void test_asub(const regex_t *preg, const char *string) { - regmatch_t rm[10]; - int rv = regexec(preg, string, __arraycount(rm), rm, 0); - if (!rv) { - char *buf; - ssize_t ss = regasub(&buf, "\\1xyz", rm, string); - assert(ss != -1); - - printf("'%s' -> '%s'\n", string, buf); - free(buf); - } else if (rv == REG_NOMATCH) - printf("%s: not-matched\n", string); - else - abort(); -} - int main(void) { printf("regex\n"); @@ -76,9 +51,6 @@ int main(void) { test_print_matches(®ex, "ABC"); - test_nsub(®ex, "ABC DEF"); - test_asub(®ex, "GHI JKL"); - regfree(®ex); rv = regcomp(®ex, "[[:upp:]]", 0); @@ -93,8 +65,6 @@ int main(void) { // CHECK: ABC: matched // CHECK: matched[0]='AB' // CHECK: matched[1]='B' - // CHECK: 'ABC DEF' -> 'Bxyz' - // CHECK: 'GHI JKL' -> 'Hxyz' // CHECK: error:{{.*}} return 0;