[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
This commit is contained in:
parent
a70184ba92
commit
58d3823086
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
|
||||
//
|
||||
// UNSUPPORTED: linux, darwin, solaris
|
||||
|
||||
#include <assert.h>
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
Loading…
Reference in New Issue