aboutsummaryrefslogtreecommitdiff
path: root/third_party/libFuzzer-make-interceptors-configurable.patch
blob: 9420c4aab09dcdb9abe664041b1d5353ae747eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
diff --git compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
index b87798603fda..10e34ee86cce 100644
--- compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
+++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
@@ -147,11 +147,18 @@ DEFINE_REAL(char *, strstr, const char *, const char *)
 DEFINE_REAL(char *, strcasestr, const char *, const char *)
 DEFINE_REAL(void *, memmem, const void *, size_t, const void *, size_t)

+extern "C" __attribute__((weak)) bool
+__sanitizer_weak_is_relevant_pc(void * caller_pc) {
+  return false;
+}
+
 ATTRIBUTE_INTERFACE int bcmp(const char *s1, const char *s2, size_t n) {
   if (!FuzzerInited)
     return internal_memcmp(s1, s2, n);
   int result = REAL(bcmp)(s1, s2, n);
-  __sanitizer_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_memcmp(caller_pc, s1, s2, n, result);
   return result;
 }

@@ -159,7 +166,9 @@ ATTRIBUTE_INTERFACE int memcmp(const void *s1, const void *s2, size_t n) {
   if (!FuzzerInited)
     return internal_memcmp(s1, s2, n);
   int result = REAL(memcmp)(s1, s2, n);
-  __sanitizer_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_memcmp(caller_pc, s1, s2, n, result);
   return result;
 }

@@ -167,7 +176,9 @@ ATTRIBUTE_INTERFACE int strncmp(const char *s1, const char *s2, size_t n) {
   if (!FuzzerInited)
     return internal_strncmp(s1, s2, n);
   int result = REAL(strncmp)(s1, s2, n);
-  __sanitizer_weak_hook_strncmp(GET_CALLER_PC(), s1, s2, n, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strncmp(caller_pc, s1, s2, n, result);
   return result;
 }

@@ -175,21 +186,27 @@ ATTRIBUTE_INTERFACE int strcmp(const char *s1, const char *s2) {
   if (!FuzzerInited)
     return internal_strcmp(s1, s2);
   int result = REAL(strcmp)(s1, s2);
-  __sanitizer_weak_hook_strcmp(GET_CALLER_PC(), s1, s2, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strcmp(caller_pc, s1, s2, result);
   return result;
 }

 ATTRIBUTE_INTERFACE int strncasecmp(const char *s1, const char *s2, size_t n) {
   ensureFuzzerInited();
   int result = REAL(strncasecmp)(s1, s2, n);
-  __sanitizer_weak_hook_strncasecmp(GET_CALLER_PC(), s1, s2, n, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strncasecmp(caller_pc, s1, s2, n, result);
   return result;
 }

 ATTRIBUTE_INTERFACE int strcasecmp(const char *s1, const char *s2) {
   ensureFuzzerInited();
   int result = REAL(strcasecmp)(s1, s2);
-  __sanitizer_weak_hook_strcasecmp(GET_CALLER_PC(), s1, s2, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strcasecmp(caller_pc, s1, s2, result);
   return result;
 }

@@ -197,14 +214,18 @@ ATTRIBUTE_INTERFACE char *strstr(const char *s1, const char *s2) {
   if (!FuzzerInited)
     return internal_strstr(s1, s2);
   char *result = REAL(strstr)(s1, s2);
-  __sanitizer_weak_hook_strstr(GET_CALLER_PC(), s1, s2, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strstr(caller_pc, s1, s2, result);
   return result;
 }

 ATTRIBUTE_INTERFACE char *strcasestr(const char *s1, const char *s2) {
   ensureFuzzerInited();
   char *result = REAL(strcasestr)(s1, s2);
-  __sanitizer_weak_hook_strcasestr(GET_CALLER_PC(), s1, s2, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_strcasestr(caller_pc, s1, s2, result);
   return result;
 }

@@ -212,7 +233,9 @@ ATTRIBUTE_INTERFACE
 void *memmem(const void *s1, size_t len1, const void *s2, size_t len2) {
   ensureFuzzerInited();
   void *result = REAL(memmem)(s1, len1, s2, len2);
-  __sanitizer_weak_hook_memmem(GET_CALLER_PC(), s1, len1, s2, len2, result);
+  void *caller_pc = GET_CALLER_PC();
+  if (__sanitizer_weak_is_relevant_pc(caller_pc))
+    __sanitizer_weak_hook_memmem(caller_pc, s1, len1, s2, len2, result);
   return result;
 }