1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 // Test whether calling certain libFuzzer's interceptors inside allocators
6 // does not cause an assertion failure.
15 static const char *buf1
= "aaaa";
16 static const char *buf2
= "bbbb";
18 static void callFuzzerInterceptors(const char *prefix
) {
19 int memcmp_result
= memcmp(buf1
, buf2
, 4);
20 if (memcmp_result
!= 0) {
21 fprintf(stderr
, "%s-MEMCMP\n", prefix
);
23 int strncmp_result
= strncmp(buf1
, buf2
, 4);
24 if (strncmp_result
!= 0) {
25 fprintf(stderr
, "%s-STRNCMP\n", prefix
);
27 int strcmp_result
= strcmp(buf1
, buf2
);
28 if (strcmp_result
!= 0) {
29 fprintf(stderr
, "%s-STRCMP\n", prefix
);
31 const char *strstr_result
= strstr(buf1
, buf2
);
32 if (strstr_result
== nullptr) {
33 fprintf(stderr
, "%s-STRSTR\n", prefix
);
37 extern "C" void *__libc_calloc(size_t, size_t);
39 extern "C" void *calloc(size_t n
, size_t elem_size
) {
40 static bool CalledOnce
= false;
42 callFuzzerInterceptors("CALLOC");
45 return __libc_calloc(n
, elem_size
);