Fix null ptr dereference of unresolved symbols on early init (linking stage)
MODIFY
qemu_mode/libcompcov/libcompcov.so.c
qemu_mode/libcompcov/libcompcov.so.c
#error "Sorry, this library is Linux-specific for now!"
#endif /* !__linux__ */
+#ifndef likely
+# define likely(x) __builtin_expect((!!(x)),1)
+#endif
+#ifndef unlikely
+# define unlikely(x) __builtin_expect((!!(x)),0)
+#endif
+
/* Change this value to tune the compare coverage */
#define MAX_CMP_LENGTH 32
@@ -199,6 +206,7 @@ static u8 __compcov_is_in_bound(const void *ptr) {
int strcmp(const char *str1, const char *str2) {
+ if (unlikely(!__libc_strcmp)) { __libc_strcmp = dlsym(RTLD_NEXT, "strcmp"); }
void *retaddr = __builtin_return_address(0);
if (__compcov_is_in_bound(retaddr) &&
@@ -227,6 +235,7 @@ int strcmp(const char *str1, const char *str2) {
int strncmp(const char *str1, const char *str2, size_t len) {
+ if (unlikely(!__libc_strncmp)) { __libc_strncmp = dlsym(RTLD_NEXT, "strncmp"); }
void *retaddr = __builtin_return_address(0);
if (__compcov_is_in_bound(retaddr) &&
@@ -256,6 +265,7 @@ int strncmp(const char *str1, const char *str2, size_t len) {
int strcasecmp(const char *str1, const char *str2) {
+ if (unlikely(!__libc_strcasecmp)) { __libc_strncasecmp = dlsym(RTLD_NEXT, "strcasecmp"); }
void *retaddr = __builtin_return_address(0);
if (__compcov_is_in_bound(retaddr) &&
@@ -286,6 +296,7 @@ int strcasecmp(const char *str1, const char *str2) {
int strncasecmp(const char *str1, const char *str2, size_t len) {
+ if (unlikely(!__libc_strncasecmp)) { __libc_strncasecmp = dlsym(RTLD_NEXT, "strncasecmp"); }
void *retaddr = __builtin_return_address(0);
if (__compcov_is_in_bound(retaddr) &&
@@ -317,6 +328,7 @@ int strncasecmp(const char *str1, const char *str2, size_t len) {
int memcmp(const void *mem1, const void *mem2, size_t len) {
+ if (unlikely(!__libc_memcmp)) { __libc_memcmp = dlsym(RTLD_NEXT, "memcmp"); }
void *retaddr = __builtin_return_address(0);
if (__compcov_is_in_bound(retaddr) &&

Fix null ptr dereference of unresolved symbols on early init (linking stage)