1 // Test the weak hooks.
2 // RUN: %clangxx %s -o %t && %run %t
4 // Must not be implemented, no other reason to install interceptors.
12 #if defined(_GNU_SOURCE)
13 #include <strings.h> // for bcmp
16 bool seen_memcmp
, seen_strncmp
, seen_strncasecmp
, seen_strcmp
, seen_strcasecmp
,
17 seen_strstr
, seen_strcasestr
, seen_memmem
;
20 void __sanitizer_weak_hook_memcmp(void *called_pc
, const void *s1
,
21 const void *s2
, size_t n
, int result
) {
24 void __sanitizer_weak_hook_strncmp(void *called_pc
, const char *s1
,
25 const char *s2
, size_t n
, int result
) {
28 void __sanitizer_weak_hook_strncasecmp(void *called_pc
, const char *s1
,
29 const char *s2
, size_t n
, int result
){
30 seen_strncasecmp
= true;
32 void __sanitizer_weak_hook_strcmp(void *called_pc
, const char *s1
,
33 const char *s2
, int result
){
36 void __sanitizer_weak_hook_strcasecmp(void *called_pc
, const char *s1
,
37 const char *s2
, int result
){
38 seen_strcasecmp
= true;
40 void __sanitizer_weak_hook_strstr(void *called_pc
, const char *s1
,
41 const char *s2
, char *result
){
44 void __sanitizer_weak_hook_strcasestr(void *called_pc
, const char *s1
,
45 const char *s2
, char *result
){
46 seen_strcasestr
= true;
48 void __sanitizer_weak_hook_memmem(void *called_pc
, const void *s1
, size_t len1
,
49 const void *s2
, size_t len2
, void *result
){
57 static volatile int int_sink
;
58 static volatile void *ptr_sink
;
61 assert(sizeof(s2
) < sizeof(s1
));
63 int_sink
= memcmp(s1
, s2
, sizeof(s2
));
66 #if (defined(__linux__) && !defined(__ANDROID__) && defined(_GNU_SOURCE)) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
68 int_sink
= bcmp(s1
, s2
, sizeof(s2
));
72 int_sink
= strncmp(s1
, s2
, sizeof(s2
));
75 int_sink
= strncasecmp(s1
, s2
, sizeof(s2
));
76 assert(seen_strncasecmp
);
78 int_sink
= strcmp(s1
, s2
);
81 int_sink
= strcasecmp(s1
, s2
);
82 assert(seen_strcasecmp
);
84 ptr_sink
= strstr(s1
, s2
);
87 ptr_sink
= strcasestr(s1
, s2
);
88 assert(seen_strcasestr
);
90 ptr_sink
= memmem(s1
, sizeof(s1
), s2
, sizeof(s2
));