about summary refs log tree commit diff
path: root/qemu_mode/libcompcov/libcompcov.so.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu_mode/libcompcov/libcompcov.so.c')
-rw-r--r--qemu_mode/libcompcov/libcompcov.so.c77
1 files changed, 19 insertions, 58 deletions
diff --git a/qemu_mode/libcompcov/libcompcov.so.c b/qemu_mode/libcompcov/libcompcov.so.c
index 52143c1f..582230db 100644
--- a/qemu_mode/libcompcov/libcompcov.so.c
+++ b/qemu_mode/libcompcov/libcompcov.so.c
@@ -19,6 +19,8 @@
 
  */
 
+#define _GNU_SOURCE
+#include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
@@ -38,13 +40,17 @@
 
 #define MAX_CMP_LENGTH 32
 
-static u8 __compcov_loaded;
-
 static void *__compcov_code_start,
             *__compcov_code_end;
 
 static u8 *__compcov_afl_map;
 
+static int (*__libc_strcmp)(const char*, const char*);
+static int (*__libc_strncmp)(const char*, const char*, size_t);
+static int (*__libc_strcasecmp)(const char*, const char*);
+static int (*__libc_strncasecmp)(const char*, const char*, size_t);
+static int (*__libc_memcmp)(const void*, const void*, size_t);
+
 static int debug_fd = -1;
 
 
@@ -59,8 +65,12 @@ static size_t __strlen2(const char *s1, const char *s2, size_t max_length) {
 /* Identify the binary boundaries in the memory mapping */
 
 static void __compcov_load(void) {
-
-  __compcov_loaded = 1;
+  
+  __libc_strcmp = dlsym(RTLD_NEXT, "strcmp");
+  __libc_strncmp = dlsym(RTLD_NEXT, "strncmp");
+  __libc_strcasecmp = dlsym(RTLD_NEXT, "strcasecmp");
+  __libc_strncasecmp = dlsym(RTLD_NEXT, "strncasecmp");
+  __libc_memcmp = dlsym(RTLD_NEXT, "memcmp");
   
   char *id_str = getenv(SHM_ENV_VAR);
   int shm_id;
@@ -153,16 +163,7 @@ int strcmp(const char* str1, const char* str2) {
     }
   }
 
-  while (1) {
-
-    unsigned char c1 = *str1, c2 = *str2;
-
-    if (c1 != c2) return (c1 > c2) ? 1 : -1;
-    if (!c1) return 0;
-    str1++; str2++;
-
-  }
-
+  return __libc_strcmp(str1, str2);
 }
 
 
@@ -187,18 +188,7 @@ int strncmp(const char* str1, const char* str2, size_t len) {
     }
   }
   
-  while (len--) {
-
-    unsigned char c1 = *str1, c2 = *str2;
-
-    if (!c1) return 0;
-    if (c1 != c2) return (c1 > c2) ? 1 : -1;
-    str1++; str2++;
-
-  }
-
-  return 0;
-
+  return __libc_strncmp(str1, str2, len);
 }
 
 
@@ -223,16 +213,7 @@ int strcasecmp(const char* str1, const char* str2) {
     }
   }
 
-  while (1) {
-
-    unsigned char c1 = tolower(*str1), c2 = tolower(*str2);
-
-    if (c1 != c2) return (c1 > c2) ? 1 : -1;
-    if (!c1) return 0;
-    str1++; str2++;
-
-  }
-
+  return __libc_strcasecmp(str1, str2);
 }
 
 
@@ -258,18 +239,7 @@ int strncasecmp(const char* str1, const char* str2, size_t len) {
     }
   }
 
-  while (len--) {
-
-    unsigned char c1 = tolower(*str1), c2 = tolower(*str2);
-
-    if (!c1) return 0;
-    if (c1 != c2) return (c1 > c2) ? 1 : -1;
-    str1++; str2++;
-
-  }
-
-  return 0;
-
+  return __libc_strncasecmp(str1, str2, len);
 }
 
 
@@ -293,16 +263,7 @@ int memcmp(const void* mem1, const void* mem2, size_t len) {
     }
   }
 
-  while (len--) {
-
-    unsigned char c1 = *(const char*)mem1, c2 = *(const char*)mem2;
-    if (c1 != c2) return (c1 > c2) ? 1 : -1;
-    mem1++; mem2++;
-
-  }
-
-  return 0;
-
+  return __libc_memcmp(mem1, mem2, len);
 }
 
 /* Init code to open init the library. */