//===-- FuzzerInterceptors.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Intercept certain libc functions to aid fuzzing. // Linked only when other RTs that define their own interceptors are not linked. //===----------------------------------------------------------------------===//
staticvoid *getFuncAddr(constchar *name, uintptr_t wrapper_addr) { void *addr = dlsym(RTLD_NEXT, name); if (!addr) { // If the lookup using RTLD_NEXT failed, the sanitizer runtime library is // later in the library search order than the DSO that we are trying to // intercept, which means that we cannot intercept this function. We still // want the address of the real definition, though, so look it up using // RTLD_DEFAULT.
addr = dlsym(RTLD_DEFAULT, name);
// In case `name' is not loaded, dlsym ends up finding the actual wrapper. // We don't want to intercept the wrapper and have it point to itself. if (reinterpret_cast<uintptr_t>(addr) == wrapper_addr)
addr = nullptr;
} return addr;
}
static size_t internal_strlen(constchar *s) {
size_t i = 0; while (s[i])
i++; return i;
}
staticchar *internal_strstr(constchar *haystack, constchar *needle) { // This is O(N^2), but we are not using it in hot places.
size_t len1 = internal_strlen(haystack);
size_t len2 = internal_strlen(needle); if (len1 < len2) return nullptr; for (size_t pos = 0; pos <= len1 - len2; pos++) { if (internal_memcmp(haystack + pos, needle, len2) == 0) returnconst_cast<char *>(haystack) + pos;
} return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.