mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-12 01:58:17 +00:00
code format qasan
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -306,6 +306,7 @@ void bzero(void *s, size_t n) {
|
||||
__libqasan_memset(s, 0, n);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void explicit_bzero(void *s, size_t n) {
|
||||
|
@ -54,28 +54,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define QASAN_DEBUG(msg...) \
|
||||
do { \
|
||||
\
|
||||
if (__qasan_debug) { \
|
||||
\
|
||||
fprintf(stderr, "==%d== ", getpid()); \
|
||||
fprintf(stderr, msg); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} while (0)
|
||||
#define QASAN_DEBUG(msg...) \
|
||||
do { \
|
||||
\
|
||||
if (__qasan_debug) { \
|
||||
\
|
||||
fprintf(stderr, "==%d== ", getpid()); \
|
||||
fprintf(stderr, msg); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
#define QASAN_DEBUG(msg...) \
|
||||
do { \
|
||||
\
|
||||
} while (0)
|
||||
#define QASAN_DEBUG(msg...) \
|
||||
do { \
|
||||
\
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#define ASSERT_DLSYM(name) \
|
||||
({ \
|
||||
\
|
||||
void* a = (void*)dlsym(RTLD_NEXT, #name); \
|
||||
void *a = (void *)dlsym(RTLD_NEXT, #name); \
|
||||
if (!a) { \
|
||||
\
|
||||
fprintf(stderr, \
|
||||
@ -95,37 +96,37 @@ void __libqasan_init_malloc(void);
|
||||
|
||||
void __libqasan_hotpatch(void);
|
||||
|
||||
size_t __libqasan_malloc_usable_size(void* ptr);
|
||||
void* __libqasan_malloc(size_t size);
|
||||
void __libqasan_free(void* ptr);
|
||||
void* __libqasan_calloc(size_t nmemb, size_t size);
|
||||
void* __libqasan_realloc(void* ptr, size_t size);
|
||||
int __libqasan_posix_memalign(void** ptr, size_t align, size_t len);
|
||||
void* __libqasan_memalign(size_t align, size_t len);
|
||||
void* __libqasan_aligned_alloc(size_t align, size_t len);
|
||||
size_t __libqasan_malloc_usable_size(void *ptr);
|
||||
void * __libqasan_malloc(size_t size);
|
||||
void __libqasan_free(void *ptr);
|
||||
void * __libqasan_calloc(size_t nmemb, size_t size);
|
||||
void * __libqasan_realloc(void *ptr, size_t size);
|
||||
int __libqasan_posix_memalign(void **ptr, size_t align, size_t len);
|
||||
void * __libqasan_memalign(size_t align, size_t len);
|
||||
void * __libqasan_aligned_alloc(size_t align, size_t len);
|
||||
|
||||
void* __libqasan_memcpy(void* dest, const void* src, size_t n);
|
||||
void* __libqasan_memmove(void* dest, const void* src, size_t n);
|
||||
void* __libqasan_memset(void* s, int c, size_t n);
|
||||
void* __libqasan_memchr(const void* s, int c, size_t n);
|
||||
void* __libqasan_memrchr(const void* s, int c, size_t n);
|
||||
size_t __libqasan_strlen(const char* s);
|
||||
size_t __libqasan_strnlen(const char* s, size_t len);
|
||||
int __libqasan_strcmp(const char* str1, const char* str2);
|
||||
int __libqasan_strncmp(const char* str1, const char* str2, size_t len);
|
||||
int __libqasan_strcasecmp(const char* str1, const char* str2);
|
||||
int __libqasan_strncasecmp(const char* str1, const char* str2, size_t len);
|
||||
int __libqasan_memcmp(const void* mem1, const void* mem2, size_t len);
|
||||
int __libqasan_bcmp(const void* mem1, const void* mem2, size_t len);
|
||||
char* __libqasan_strstr(const char* haystack, const char* needle);
|
||||
char* __libqasan_strcasestr(const char* haystack, const char* needle);
|
||||
void* __libqasan_memmem(const void* haystack, size_t haystack_len,
|
||||
const void* needle, size_t needle_len);
|
||||
char* __libqasan_strchr(const char* s, int c);
|
||||
char* __libqasan_strrchr(const char* s, int c);
|
||||
size_t __libqasan_wcslen(const wchar_t* s);
|
||||
wchar_t* __libqasan_wcscpy(wchar_t* d, const wchar_t* s);
|
||||
int __libqasan_wcscmp(const wchar_t* s1, const wchar_t* s2);
|
||||
void * __libqasan_memcpy(void *dest, const void *src, size_t n);
|
||||
void * __libqasan_memmove(void *dest, const void *src, size_t n);
|
||||
void * __libqasan_memset(void *s, int c, size_t n);
|
||||
void * __libqasan_memchr(const void *s, int c, size_t n);
|
||||
void * __libqasan_memrchr(const void *s, int c, size_t n);
|
||||
size_t __libqasan_strlen(const char *s);
|
||||
size_t __libqasan_strnlen(const char *s, size_t len);
|
||||
int __libqasan_strcmp(const char *str1, const char *str2);
|
||||
int __libqasan_strncmp(const char *str1, const char *str2, size_t len);
|
||||
int __libqasan_strcasecmp(const char *str1, const char *str2);
|
||||
int __libqasan_strncasecmp(const char *str1, const char *str2, size_t len);
|
||||
int __libqasan_memcmp(const void *mem1, const void *mem2, size_t len);
|
||||
int __libqasan_bcmp(const void *mem1, const void *mem2, size_t len);
|
||||
char * __libqasan_strstr(const char *haystack, const char *needle);
|
||||
char * __libqasan_strcasestr(const char *haystack, const char *needle);
|
||||
void * __libqasan_memmem(const void *haystack, size_t haystack_len,
|
||||
const void *needle, size_t needle_len);
|
||||
char * __libqasan_strchr(const char *s, int c);
|
||||
char * __libqasan_strrchr(const char *s, int c);
|
||||
size_t __libqasan_wcslen(const wchar_t *s);
|
||||
wchar_t *__libqasan_wcscpy(wchar_t *d, const wchar_t *s);
|
||||
int __libqasan_wcscmp(const wchar_t *s1, const wchar_t *s2);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -50,9 +50,9 @@ typedef struct {
|
||||
struct chunk_begin {
|
||||
|
||||
size_t requested_size;
|
||||
void* aligned_orig; // NULL if not aligned
|
||||
struct chunk_begin* next;
|
||||
struct chunk_begin* prev;
|
||||
void * aligned_orig; // NULL if not aligned
|
||||
struct chunk_begin *next;
|
||||
struct chunk_begin *prev;
|
||||
char redzone[REDZONE_SIZE];
|
||||
|
||||
};
|
||||
@ -66,29 +66,29 @@ struct chunk_struct {
|
||||
};
|
||||
|
||||
// From dlmalloc.c
|
||||
void* dlmalloc(size_t);
|
||||
void dlfree(void*);
|
||||
void *dlmalloc(size_t);
|
||||
void dlfree(void *);
|
||||
|
||||
int __libqasan_malloc_initialized;
|
||||
|
||||
static struct chunk_begin* quarantine_top;
|
||||
static struct chunk_begin* quarantine_end;
|
||||
static struct chunk_begin *quarantine_top;
|
||||
static struct chunk_begin *quarantine_end;
|
||||
static size_t quarantine_bytes;
|
||||
|
||||
#ifdef __BIONIC__
|
||||
static pthread_mutex_t quarantine_lock;
|
||||
#define LOCK_TRY pthread_mutex_trylock
|
||||
#define LOCK_INIT pthread_mutex_init
|
||||
#define LOCK_UNLOCK pthread_mutex_unlock
|
||||
static pthread_mutex_t quarantine_lock;
|
||||
#define LOCK_TRY pthread_mutex_trylock
|
||||
#define LOCK_INIT pthread_mutex_init
|
||||
#define LOCK_UNLOCK pthread_mutex_unlock
|
||||
#else
|
||||
static pthread_spinlock_t quarantine_lock;
|
||||
#define LOCK_TRY pthread_spin_trylock
|
||||
#define LOCK_INIT pthread_spin_init
|
||||
#define LOCK_UNLOCK pthread_spin_unlock
|
||||
static pthread_spinlock_t quarantine_lock;
|
||||
#define LOCK_TRY pthread_spin_trylock
|
||||
#define LOCK_INIT pthread_spin_init
|
||||
#define LOCK_UNLOCK pthread_spin_unlock
|
||||
#endif
|
||||
|
||||
// need qasan disabled
|
||||
static int quanratine_push(struct chunk_begin* ck) {
|
||||
static int quanratine_push(struct chunk_begin *ck) {
|
||||
|
||||
if (ck->requested_size >= QUARANTINE_MAX_BYTES) return 0;
|
||||
|
||||
@ -96,7 +96,7 @@ static int quanratine_push(struct chunk_begin* ck) {
|
||||
|
||||
while (ck->requested_size + quarantine_bytes >= QUARANTINE_MAX_BYTES) {
|
||||
|
||||
struct chunk_begin* tmp = quarantine_end;
|
||||
struct chunk_begin *tmp = quarantine_end;
|
||||
quarantine_end = tmp->prev;
|
||||
|
||||
quarantine_bytes -= tmp->requested_size;
|
||||
@ -131,29 +131,24 @@ void __libqasan_init_malloc(void) {
|
||||
|
||||
}
|
||||
|
||||
size_t __libqasan_malloc_usable_size(void* ptr) {
|
||||
size_t __libqasan_malloc_usable_size(void *ptr) {
|
||||
|
||||
char* p = ptr;
|
||||
char *p = ptr;
|
||||
p -= sizeof(struct chunk_begin);
|
||||
|
||||
return ((struct chunk_begin*)p)->requested_size;
|
||||
return ((struct chunk_begin *)p)->requested_size;
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_malloc(size_t size) {
|
||||
void *__libqasan_malloc(size_t size) {
|
||||
|
||||
if (!__libqasan_malloc_initialized) {
|
||||
|
||||
__libqasan_init_malloc();
|
||||
if (!__libqasan_malloc_initialized) { __libqasan_init_malloc(); }
|
||||
|
||||
}
|
||||
|
||||
if (!__libqasan_malloc_initialized)
|
||||
__libqasan_init_malloc();
|
||||
if (!__libqasan_malloc_initialized) __libqasan_init_malloc();
|
||||
|
||||
int state = QASAN_SWAP(QASAN_DISABLED); // disable qasan for this thread
|
||||
|
||||
struct chunk_begin* p = dlmalloc(sizeof(struct chunk_struct) + size);
|
||||
struct chunk_begin *p = dlmalloc(sizeof(struct chunk_struct) + size);
|
||||
|
||||
QASAN_SWAP(state);
|
||||
|
||||
@ -165,14 +160,14 @@ void* __libqasan_malloc(size_t size) {
|
||||
p->aligned_orig = NULL;
|
||||
p->next = p->prev = NULL;
|
||||
|
||||
QASAN_ALLOC(&p[1], (char*)&p[1] + size);
|
||||
QASAN_ALLOC(&p[1], (char *)&p[1] + size);
|
||||
QASAN_POISON(p->redzone, REDZONE_SIZE, ASAN_HEAP_LEFT_RZ);
|
||||
if (size & (ALLOC_ALIGN_SIZE - 1))
|
||||
QASAN_POISON((char*)&p[1] + size,
|
||||
QASAN_POISON((char *)&p[1] + size,
|
||||
(size & ~(ALLOC_ALIGN_SIZE - 1)) + 8 - size + REDZONE_SIZE,
|
||||
ASAN_HEAP_RIGHT_RZ);
|
||||
else
|
||||
QASAN_POISON((char*)&p[1] + size, REDZONE_SIZE, ASAN_HEAP_RIGHT_RZ);
|
||||
QASAN_POISON((char *)&p[1] + size, REDZONE_SIZE, ASAN_HEAP_RIGHT_RZ);
|
||||
|
||||
__builtin_memset(&p[1], 0xff, size);
|
||||
|
||||
@ -180,11 +175,11 @@ void* __libqasan_malloc(size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void __libqasan_free(void* ptr) {
|
||||
void __libqasan_free(void *ptr) {
|
||||
|
||||
if (!ptr) return;
|
||||
|
||||
struct chunk_begin* p = ptr;
|
||||
struct chunk_begin *p = ptr;
|
||||
p -= 1;
|
||||
|
||||
size_t n = p->requested_size;
|
||||
@ -211,11 +206,11 @@ void __libqasan_free(void* ptr) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_calloc(size_t nmemb, size_t size) {
|
||||
void *__libqasan_calloc(size_t nmemb, size_t size) {
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
char* p = __libqasan_malloc(size);
|
||||
char *p = __libqasan_malloc(size);
|
||||
if (!p) return NULL;
|
||||
|
||||
__builtin_memset(p, 0, size);
|
||||
@ -224,14 +219,14 @@ void* __libqasan_calloc(size_t nmemb, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_realloc(void* ptr, size_t size) {
|
||||
void *__libqasan_realloc(void *ptr, size_t size) {
|
||||
|
||||
char* p = __libqasan_malloc(size);
|
||||
char *p = __libqasan_malloc(size);
|
||||
if (!p) return NULL;
|
||||
|
||||
if (!ptr) return p;
|
||||
|
||||
size_t n = ((struct chunk_begin*)ptr)[-1].requested_size;
|
||||
size_t n = ((struct chunk_begin *)ptr)[-1].requested_size;
|
||||
if (size < n) n = size;
|
||||
|
||||
__builtin_memcpy(p, ptr, n);
|
||||
@ -241,9 +236,9 @@ void* __libqasan_realloc(void* ptr, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_posix_memalign(void** ptr, size_t align, size_t len) {
|
||||
int __libqasan_posix_memalign(void **ptr, size_t align, size_t len) {
|
||||
|
||||
if ((align % 2) || (align % sizeof(void*))) return EINVAL;
|
||||
if ((align % 2) || (align % sizeof(void *))) return EINVAL;
|
||||
if (len == 0) {
|
||||
|
||||
*ptr = NULL;
|
||||
@ -257,7 +252,7 @@ int __libqasan_posix_memalign(void** ptr, size_t align, size_t len) {
|
||||
|
||||
int state = QASAN_SWAP(QASAN_DISABLED); // disable qasan for this thread
|
||||
|
||||
char* orig = dlmalloc(sizeof(struct chunk_struct) + size);
|
||||
char *orig = dlmalloc(sizeof(struct chunk_struct) + size);
|
||||
|
||||
QASAN_SWAP(state);
|
||||
|
||||
@ -265,10 +260,10 @@ int __libqasan_posix_memalign(void** ptr, size_t align, size_t len) {
|
||||
|
||||
QASAN_UNPOISON(orig, sizeof(struct chunk_struct) + size);
|
||||
|
||||
char* data = orig + sizeof(struct chunk_begin);
|
||||
char *data = orig + sizeof(struct chunk_begin);
|
||||
data += align - ((uintptr_t)data % align);
|
||||
|
||||
struct chunk_begin* p = (struct chunk_begin*)data - 1;
|
||||
struct chunk_begin *p = (struct chunk_begin *)data - 1;
|
||||
|
||||
p->requested_size = len;
|
||||
p->aligned_orig = orig;
|
||||
@ -291,9 +286,9 @@ int __libqasan_posix_memalign(void** ptr, size_t align, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memalign(size_t align, size_t len) {
|
||||
void *__libqasan_memalign(size_t align, size_t len) {
|
||||
|
||||
void* ret = NULL;
|
||||
void *ret = NULL;
|
||||
|
||||
__libqasan_posix_memalign(&ret, align, len);
|
||||
|
||||
@ -301,9 +296,9 @@ void* __libqasan_memalign(size_t align, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_aligned_alloc(size_t align, size_t len) {
|
||||
void *__libqasan_aligned_alloc(size_t align, size_t len) {
|
||||
|
||||
void* ret = NULL;
|
||||
void *ret = NULL;
|
||||
|
||||
if ((len % align)) return NULL;
|
||||
|
||||
|
@ -28,12 +28,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
uint8_t *__libqasan_patch_jump(uint8_t *addr, uint8_t *dest) {
|
||||
|
||||
// mov rax, dest
|
||||
addr[0] = 0x48;
|
||||
addr[1] = 0xb8;
|
||||
*(uint8_t**)&addr[2] = dest;
|
||||
*(uint8_t **)&addr[2] = dest;
|
||||
|
||||
// jmp rax
|
||||
addr[10] = 0xff;
|
||||
@ -45,11 +45,11 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
|
||||
#elif __i386__
|
||||
|
||||
uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
uint8_t *__libqasan_patch_jump(uint8_t *addr, uint8_t *dest) {
|
||||
|
||||
// mov eax, dest
|
||||
addr[0] = 0xb8;
|
||||
*(uint8_t**)&addr[1] = dest;
|
||||
*(uint8_t **)&addr[1] = dest;
|
||||
|
||||
// jmp eax
|
||||
addr[5] = 0xff;
|
||||
@ -64,7 +64,7 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
// in ARM, r12 is a scratch register used by the linker to jump,
|
||||
// so let's use it in our stub
|
||||
|
||||
uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
uint8_t *__libqasan_patch_jump(uint8_t *addr, uint8_t *dest) {
|
||||
|
||||
// ldr r12, OFF
|
||||
addr[0] = 0x0;
|
||||
@ -79,7 +79,7 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
addr[7] = 0xe0;
|
||||
|
||||
// OFF: .word dest
|
||||
*(uint32_t*)&addr[8] = (uint32_t)dest;
|
||||
*(uint32_t *)&addr[8] = (uint32_t)dest;
|
||||
|
||||
return &addr[12];
|
||||
|
||||
@ -90,7 +90,7 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
// in ARM64, x16 is a scratch register used by the linker to jump,
|
||||
// so let's use it in our stub
|
||||
|
||||
uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
uint8_t *__libqasan_patch_jump(uint8_t *addr, uint8_t *dest) {
|
||||
|
||||
// ldr x16, OFF
|
||||
addr[0] = 0x50;
|
||||
@ -105,7 +105,7 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
addr[7] = 0xd6;
|
||||
|
||||
// OFF: .dword dest
|
||||
*(uint64_t*)&addr[8] = (uint64_t)dest;
|
||||
*(uint64_t *)&addr[8] = (uint64_t)dest;
|
||||
|
||||
return &addr[16];
|
||||
|
||||
@ -113,7 +113,7 @@ uint8_t* __libqasan_patch_jump(uint8_t* addr, uint8_t* dest) {
|
||||
|
||||
#else
|
||||
|
||||
#define CANNOT_HOTPATCH
|
||||
#define CANNOT_HOTPATCH
|
||||
|
||||
#endif
|
||||
|
||||
@ -130,8 +130,8 @@ int libc_perms;
|
||||
|
||||
static void find_libc(void) {
|
||||
|
||||
FILE* fp;
|
||||
char* line = NULL;
|
||||
FILE * fp;
|
||||
char * line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
@ -156,8 +156,8 @@ static void find_libc(void) {
|
||||
if (flag_x == 'x' && (__libqasan_strstr(path, "/libc.so") ||
|
||||
__libqasan_strstr(path, "/libc-"))) {
|
||||
|
||||
libc_start = (void*)min;
|
||||
libc_end = (void*)max;
|
||||
libc_start = (void *)min;
|
||||
libc_end = (void *)max;
|
||||
|
||||
libc_perms = PROT_EXEC;
|
||||
if (flag_w == 'w') libc_perms |= PROT_WRITE;
|
||||
@ -190,30 +190,30 @@ void __libqasan_hotpatch(void) {
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
|
||||
return;
|
||||
|
||||
void* libc = dlopen("libc.so.6", RTLD_LAZY);
|
||||
void *libc = dlopen("libc.so.6", RTLD_LAZY);
|
||||
|
||||
#define HOTPATCH(fn) \
|
||||
uint8_t* p_##fn = (uint8_t*)dlsym(libc, #fn); \
|
||||
if (p_##fn) __libqasan_patch_jump(p_##fn, (uint8_t*)&(fn));
|
||||
#define HOTPATCH(fn) \
|
||||
uint8_t *p_##fn = (uint8_t *)dlsym(libc, #fn); \
|
||||
if (p_##fn) __libqasan_patch_jump(p_##fn, (uint8_t *)&(fn));
|
||||
|
||||
HOTPATCH(memcmp)
|
||||
HOTPATCH(memmove)
|
||||
|
||||
uint8_t* p_memcpy = (uint8_t*)dlsym(libc, "memcpy");
|
||||
uint8_t *p_memcpy = (uint8_t *)dlsym(libc, "memcpy");
|
||||
// fuck you libc
|
||||
if (p_memcpy && p_memmove != p_memcpy)
|
||||
__libqasan_patch_jump(p_memcpy, (uint8_t*)&memcpy);
|
||||
__libqasan_patch_jump(p_memcpy, (uint8_t *)&memcpy);
|
||||
|
||||
HOTPATCH(memchr)
|
||||
HOTPATCH(memrchr)
|
||||
HOTPATCH(memmem)
|
||||
#ifndef __BIONIC__
|
||||
#ifndef __BIONIC__
|
||||
HOTPATCH(bzero)
|
||||
HOTPATCH(explicit_bzero)
|
||||
HOTPATCH(mempcpy)
|
||||
HOTPATCH(bcmp)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
HOTPATCH(strchr)
|
||||
HOTPATCH(strrchr)
|
||||
HOTPATCH(strcasecmp)
|
||||
@ -233,7 +233,7 @@ void __libqasan_hotpatch(void) {
|
||||
HOTPATCH(wcscpy)
|
||||
HOTPATCH(wcscmp)
|
||||
|
||||
#undef HOTPATCH
|
||||
#undef HOTPATCH
|
||||
|
||||
mprotect(libc_start, libc_end - libc_start, libc_perms);
|
||||
|
||||
|
@ -26,10 +26,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libqasan.h"
|
||||
#include <ctype.h>
|
||||
|
||||
void* __libqasan_memcpy(void* dest, const void* src, size_t n) {
|
||||
void *__libqasan_memcpy(void *dest, const void *src, size_t n) {
|
||||
|
||||
unsigned char* d = dest;
|
||||
const unsigned char* s = src;
|
||||
unsigned char * d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
||||
if (!n) return dest;
|
||||
|
||||
@ -45,10 +45,10 @@ void* __libqasan_memcpy(void* dest, const void* src, size_t n) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memmove(void* dest, const void* src, size_t n) {
|
||||
void *__libqasan_memmove(void *dest, const void *src, size_t n) {
|
||||
|
||||
unsigned char* d = dest;
|
||||
const unsigned char* s = src;
|
||||
unsigned char * d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
||||
if (!n) return dest;
|
||||
|
||||
@ -65,18 +65,18 @@ void* __libqasan_memmove(void* dest, const void* src, size_t n) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memset(void* s, int c, size_t n) {
|
||||
void *__libqasan_memset(void *s, int c, size_t n) {
|
||||
|
||||
unsigned char* b = s;
|
||||
unsigned char *b = s;
|
||||
while (n--)
|
||||
*(b++) = (unsigned char)c;
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memchr(const void* s, int c, size_t n) {
|
||||
void *__libqasan_memchr(const void *s, int c, size_t n) {
|
||||
|
||||
unsigned char* m = (unsigned char*)s;
|
||||
unsigned char *m = (unsigned char *)s;
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i)
|
||||
if (m[i] == (unsigned char)c) return &m[i];
|
||||
@ -84,9 +84,9 @@ void* __libqasan_memchr(const void* s, int c, size_t n) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memrchr(const void* s, int c, size_t n) {
|
||||
void *__libqasan_memrchr(const void *s, int c, size_t n) {
|
||||
|
||||
unsigned char* m = (unsigned char*)s;
|
||||
unsigned char *m = (unsigned char *)s;
|
||||
long i;
|
||||
for (i = n; i >= 0; --i)
|
||||
if (m[i] == (unsigned char)c) return &m[i];
|
||||
@ -94,16 +94,16 @@ void* __libqasan_memrchr(const void* s, int c, size_t n) {
|
||||
|
||||
}
|
||||
|
||||
size_t __libqasan_strlen(const char* s) {
|
||||
size_t __libqasan_strlen(const char *s) {
|
||||
|
||||
const char* i = s;
|
||||
const char *i = s;
|
||||
while (*(i++))
|
||||
;
|
||||
return i - s - 1;
|
||||
|
||||
}
|
||||
|
||||
size_t __libqasan_strnlen(const char* s, size_t len) {
|
||||
size_t __libqasan_strnlen(const char *s, size_t len) {
|
||||
|
||||
size_t r = 0;
|
||||
while (len-- && *(s++))
|
||||
@ -112,7 +112,7 @@ size_t __libqasan_strnlen(const char* s, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_strcmp(const char* str1, const char* str2) {
|
||||
int __libqasan_strcmp(const char *str1, const char *str2) {
|
||||
|
||||
while (1) {
|
||||
|
||||
@ -129,7 +129,7 @@ int __libqasan_strcmp(const char* str1, const char* str2) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_strncmp(const char* str1, const char* str2, size_t len) {
|
||||
int __libqasan_strncmp(const char *str1, const char *str2, size_t len) {
|
||||
|
||||
while (len--) {
|
||||
|
||||
@ -146,7 +146,7 @@ int __libqasan_strncmp(const char* str1, const char* str2, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_strcasecmp(const char* str1, const char* str2) {
|
||||
int __libqasan_strcasecmp(const char *str1, const char *str2) {
|
||||
|
||||
while (1) {
|
||||
|
||||
@ -163,7 +163,7 @@ int __libqasan_strcasecmp(const char* str1, const char* str2) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_strncasecmp(const char* str1, const char* str2, size_t len) {
|
||||
int __libqasan_strncasecmp(const char *str1, const char *str2, size_t len) {
|
||||
|
||||
while (len--) {
|
||||
|
||||
@ -180,10 +180,10 @@ int __libqasan_strncasecmp(const char* str1, const char* str2, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_memcmp(const void* mem1, const void* mem2, size_t len) {
|
||||
int __libqasan_memcmp(const void *mem1, const void *mem2, size_t len) {
|
||||
|
||||
const char* strmem1 = (const char*)mem1;
|
||||
const char* strmem2 = (const char*)mem2;
|
||||
const char *strmem1 = (const char *)mem1;
|
||||
const char *strmem2 = (const char *)mem2;
|
||||
|
||||
while (len--) {
|
||||
|
||||
@ -198,10 +198,10 @@ int __libqasan_memcmp(const void* mem1, const void* mem2, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_bcmp(const void* mem1, const void* mem2, size_t len) {
|
||||
int __libqasan_bcmp(const void *mem1, const void *mem2, size_t len) {
|
||||
|
||||
const char* strmem1 = (const char*)mem1;
|
||||
const char* strmem2 = (const char*)mem2;
|
||||
const char *strmem1 = (const char *)mem1;
|
||||
const char *strmem2 = (const char *)mem2;
|
||||
|
||||
while (len--) {
|
||||
|
||||
@ -216,17 +216,17 @@ int __libqasan_bcmp(const void* mem1, const void* mem2, size_t len) {
|
||||
|
||||
}
|
||||
|
||||
char* __libqasan_strstr(const char* haystack, const char* needle) {
|
||||
char *__libqasan_strstr(const char *haystack, const char *needle) {
|
||||
|
||||
do {
|
||||
|
||||
const char* n = needle;
|
||||
const char* h = haystack;
|
||||
const char *n = needle;
|
||||
const char *h = haystack;
|
||||
|
||||
while (*n && *h && *n == *h)
|
||||
n++, h++;
|
||||
|
||||
if (!*n) return (char*)haystack;
|
||||
if (!*n) return (char *)haystack;
|
||||
|
||||
} while (*(haystack++));
|
||||
|
||||
@ -234,17 +234,17 @@ char* __libqasan_strstr(const char* haystack, const char* needle) {
|
||||
|
||||
}
|
||||
|
||||
char* __libqasan_strcasestr(const char* haystack, const char* needle) {
|
||||
char *__libqasan_strcasestr(const char *haystack, const char *needle) {
|
||||
|
||||
do {
|
||||
|
||||
const char* n = needle;
|
||||
const char* h = haystack;
|
||||
const char *n = needle;
|
||||
const char *h = haystack;
|
||||
|
||||
while (*n && *h && tolower(*n) == tolower(*h))
|
||||
n++, h++;
|
||||
|
||||
if (!*n) return (char*)haystack;
|
||||
if (!*n) return (char *)haystack;
|
||||
|
||||
} while (*(haystack++));
|
||||
|
||||
@ -252,22 +252,22 @@ char* __libqasan_strcasestr(const char* haystack, const char* needle) {
|
||||
|
||||
}
|
||||
|
||||
void* __libqasan_memmem(const void* haystack, size_t haystack_len,
|
||||
const void* needle, size_t needle_len) {
|
||||
void *__libqasan_memmem(const void *haystack, size_t haystack_len,
|
||||
const void *needle, size_t needle_len) {
|
||||
|
||||
const char* n = (const char*)needle;
|
||||
const char* h = (const char*)haystack;
|
||||
const char *n = (const char *)needle;
|
||||
const char *h = (const char *)haystack;
|
||||
if (haystack_len < needle_len) return 0;
|
||||
if (needle_len == 0) return (void*)haystack;
|
||||
if (needle_len == 0) return (void *)haystack;
|
||||
if (needle_len == 1) return memchr(haystack, *n, haystack_len);
|
||||
|
||||
const char* end = h + (haystack_len - needle_len);
|
||||
const char *end = h + (haystack_len - needle_len);
|
||||
|
||||
do {
|
||||
|
||||
if (*h == *n) {
|
||||
|
||||
if (memcmp(h, n, needle_len) == 0) return (void*)h;
|
||||
if (memcmp(h, n, needle_len) == 0) return (void *)h;
|
||||
|
||||
}
|
||||
|
||||
@ -277,26 +277,26 @@ void* __libqasan_memmem(const void* haystack, size_t haystack_len,
|
||||
|
||||
}
|
||||
|
||||
char* __libqasan_strchr(const char* s, int c) {
|
||||
char *__libqasan_strchr(const char *s, int c) {
|
||||
|
||||
while (*s != (char)c)
|
||||
if (!*s++) return 0;
|
||||
return (char*)s;
|
||||
return (char *)s;
|
||||
|
||||
}
|
||||
|
||||
char* __libqasan_strrchr(const char* s, int c) {
|
||||
char *__libqasan_strrchr(const char *s, int c) {
|
||||
|
||||
char* r = NULL;
|
||||
char *r = NULL;
|
||||
do
|
||||
if (*s == (char)c) r = (char*)s;
|
||||
if (*s == (char)c) r = (char *)s;
|
||||
while (*s++);
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
size_t __libqasan_wcslen(const wchar_t* s) {
|
||||
size_t __libqasan_wcslen(const wchar_t *s) {
|
||||
|
||||
size_t len = 0;
|
||||
|
||||
@ -313,16 +313,16 @@ size_t __libqasan_wcslen(const wchar_t* s) {
|
||||
|
||||
}
|
||||
|
||||
wchar_t* __libqasan_wcscpy(wchar_t* d, const wchar_t* s) {
|
||||
wchar_t *__libqasan_wcscpy(wchar_t *d, const wchar_t *s) {
|
||||
|
||||
wchar_t* a = d;
|
||||
wchar_t *a = d;
|
||||
while ((*d++ = *s++))
|
||||
;
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
int __libqasan_wcscmp(const wchar_t* s1, const wchar_t* s2) {
|
||||
int __libqasan_wcscmp(const wchar_t *s1, const wchar_t *s2) {
|
||||
|
||||
wchar_t c1, c2;
|
||||
do {
|
||||
|
Reference in New Issue
Block a user