Added implementation of tolower in libqasan (based on BIONIC's implementation). This is to make LibAFL more compiler agnostic as this function can be named differently sometimes. (#2421)

Co-authored-by: Sofyan Aarrass <s.aarrass@secura.com>
This commit is contained in:
Zofyan 2024-07-22 15:45:32 +02:00 committed by GitHub
parent 0999ac5003
commit 0dc94a48c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -128,9 +128,14 @@ int __libqasan_strncmp(const char *str1, const char *str2, size_t len) {
return 0;
}
unsigned char __libqasan_tolower(unsigned char c) {
if (c >= 'A' && c <= 'Z') return c | 0x20;
return c;
}
int __libqasan_strcasecmp(const char *str1, const char *str2) {
while (1) {
const unsigned char c1 = tolower(*str1), c2 = tolower(*str2);
const unsigned char c1 = __libqasan_tolower(*str1), c2 = __libqasan_tolower(*str2);
if (c1 != c2) { return c1 - c2; }
if (!c1) { return 0; }
@ -143,7 +148,7 @@ int __libqasan_strcasecmp(const char *str1, const char *str2) {
int __libqasan_strncasecmp(const char *str1, const char *str2, size_t len) {
while (len--) {
const unsigned char c1 = tolower(*str1), c2 = tolower(*str2);
const unsigned char c1 = __libqasan_tolower(*str1), c2 = __libqasan_tolower(*str2);
if (c1 != c2) { return c1 - c2; }
if (!c1) { return 0; }
@ -204,7 +209,7 @@ char *__libqasan_strcasestr(const char *haystack, const char *needle) {
const char *n = needle;
const char *h = haystack;
while (*n && *h && tolower(*n) == tolower(*h)) {
while (*n && *h && __libqasan_tolower(*n) == __libqasan_tolower(*h)) {
n++;
h++;
}