"Fossies" - the Fresh Open Source Software Archive

Member "honggfuzz-2.2/libhfuzz/memorycmp.c" (23 Apr 2020, 18730 Bytes) of package /linux/privat/honggfuzz-2.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "memorycmp.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.1_vs_2.2.

    1 #include <ctype.h>
    2 #include <inttypes.h>
    3 #include <stdbool.h>
    4 #include <stdint.h>
    5 #include <stdio.h>
    6 #include <string.h>
    7 #include <unistd.h>
    8 
    9 #include "libhfcommon/common.h"
   10 #include "libhfcommon/util.h"
   11 #include "libhfuzz/instrument.h"
   12 
   13 #if !defined(__CYGWIN__)
   14 __attribute__((visibility("hidden")))
   15 #endif /* !defined(__CYGWIN__) */
   16 __attribute__((used)) const char* const LIBHFUZZ_module_memorycmp = "LIBHFUZZ_module_memorycmp";
   17 
   18 /*
   19  * util_getProgAddr() check is quite costly, and it lowers the fuzzing speed typically by a factor
   20  * of 2, but keep it true for now
   21  */
   22 #define HF_TEST_ADDR_CMPHASH true
   23 
   24 static inline uintptr_t HF_cmphash(uintptr_t addr, const void* s1, const void* s2) {
   25     if (HF_TEST_ADDR_CMPHASH && util_getProgAddr(s1) == LHFC_ADDR_RO) {
   26         addr ^= ((uintptr_t)s1 << 2);
   27     }
   28     if (HF_TEST_ADDR_CMPHASH && util_getProgAddr(s2) == LHFC_ADDR_RO) {
   29         addr ^= ((uintptr_t)s2 << 4);
   30     }
   31     return addr;
   32 }
   33 
   34 static inline int HF_strcmp(const char* s1, const char* s2, uintptr_t addr) {
   35     size_t i;
   36     for (i = 0; s1[i] == s2[i]; i++) {
   37         if (s1[i] == '\0' || s2[i] == '\0') {
   38             break;
   39         }
   40     }
   41 
   42     instrumentUpdateCmpMap(HF_cmphash(addr, s1, s2), i);
   43     instrumentAddConstStr(s1);
   44     instrumentAddConstStr(s2);
   45     return (unsigned char)s1[i] - (unsigned char)s2[i];
   46 }
   47 
   48 static inline int HF_strcasecmp(
   49     const char* s1, const char* s2, int (*cmp_func)(int), uintptr_t addr) {
   50     size_t i;
   51     for (i = 0; cmp_func((unsigned char)s1[i]) == cmp_func((unsigned char)s2[i]); i++) {
   52         if (s1[i] == '\0' || s2[i] == '\0') {
   53             break;
   54         }
   55     }
   56 
   57     instrumentUpdateCmpMap(HF_cmphash(addr, s1, s2), i);
   58     instrumentAddConstStr(s1);
   59     instrumentAddConstStr(s2);
   60     return cmp_func((unsigned char)s1[i]) - cmp_func((unsigned char)s2[i]);
   61 }
   62 
   63 static inline int HF_strncmp(
   64     const char* s1, const char* s2, size_t n, bool constfb, uintptr_t addr) {
   65     size_t i;
   66     for (i = 0; i < n; i++) {
   67         if ((s1[i] != s2[i]) || s1[i] == '\0' || s2[i] == '\0') {
   68             break;
   69         }
   70     }
   71 
   72     instrumentUpdateCmpMap(HF_cmphash(addr, s1, s2), i);
   73     if (constfb) {
   74         instrumentAddConstStrN(s1, n);
   75         instrumentAddConstStrN(s2, n);
   76     }
   77 
   78     if (i == n) {
   79         return 0;
   80     }
   81 
   82     return (unsigned char)s1[i] - (unsigned char)s2[i];
   83 }
   84 
   85 static inline int HF_strncasecmp(
   86     const char* s1, const char* s2, size_t n, int (*cmp_func)(int), bool constfb, uintptr_t addr) {
   87     size_t i;
   88     for (i = 0; i < n; i++) {
   89         if ((cmp_func((unsigned char)s1[i]) != cmp_func((unsigned char)s2[i])) || s1[i] == '\0' ||
   90             s2[i] == '\0') {
   91             break;
   92         }
   93     }
   94 
   95     instrumentUpdateCmpMap(HF_cmphash(addr, s1, s2), i);
   96     if (constfb) {
   97         instrumentAddConstStrN(s1, n);
   98         instrumentAddConstStrN(s2, n);
   99     }
  100 
  101     if (i == n) {
  102         return 0;
  103     }
  104 
  105     return cmp_func((unsigned char)s1[i]) - cmp_func((unsigned char)s2[i]);
  106 }
  107 
  108 static inline char* HF_strstr(const char* haystack, const char* needle, uintptr_t addr) {
  109     size_t needle_len = __builtin_strlen(needle);
  110     if (needle_len == 0) {
  111         return (char*)haystack;
  112     }
  113 
  114     instrumentAddConstStr(needle);
  115 
  116     const char* h = haystack;
  117     for (; (h = __builtin_strchr(h, needle[0])) != NULL; h++) {
  118         if (HF_strncmp(h, needle, needle_len, /* constfb= */ false, addr) == 0) {
  119             return (char*)h;
  120         }
  121     }
  122 
  123     return NULL;
  124 }
  125 
  126 static inline char* HF_strcasestr(
  127     const char* haystack, const char* needle, int (*cmp_func)(int), uintptr_t addr) {
  128     size_t needle_len = __builtin_strlen(needle);
  129     if (needle_len == 0) {
  130         return (char*)haystack;
  131     }
  132 
  133     instrumentAddConstStr(needle);
  134 
  135     for (size_t i = 0; haystack[i]; i++) {
  136         if (HF_strncasecmp(
  137                 &haystack[i], needle, needle_len, cmp_func, /* constfb= */ false, addr) == 0) {
  138             return (char*)(&haystack[i]);
  139         }
  140     }
  141 
  142     return NULL;
  143 }
  144 
  145 static inline int HF_memcmp(
  146     const void* m1, const void* m2, size_t n, bool constfb, uintptr_t addr) {
  147     const unsigned char* s1 = (const unsigned char*)m1;
  148     const unsigned char* s2 = (const unsigned char*)m2;
  149 
  150     size_t i;
  151     for (i = 0; i < n; i++) {
  152         if (s1[i] != s2[i]) {
  153             break;
  154         }
  155     }
  156 
  157     instrumentUpdateCmpMap(HF_cmphash(addr, m1, m2), i);
  158     if (constfb) {
  159         instrumentAddConstMem(m1, n, /* check_if_ro= */ true);
  160         instrumentAddConstMem(m2, n, /* check_if_ro= */ true);
  161     }
  162 
  163     if (i == n) {
  164         return 0;
  165     }
  166 
  167     return (unsigned char)s1[i] - (unsigned char)s2[i];
  168 }
  169 
  170 static inline void* HF_memmem(const void* haystack, size_t haystacklen, const void* needle,
  171     size_t needlelen, uintptr_t addr) {
  172     if (needlelen > haystacklen) {
  173         return NULL;
  174     }
  175     if (needlelen == 0) {
  176         return (void*)haystack;
  177     }
  178 
  179     instrumentAddConstMem(needle, needlelen, /* check_if_ro= */ true);
  180 
  181     const char* h = haystack;
  182     for (size_t i = 0; i <= (haystacklen - needlelen); i++) {
  183         if (HF_memcmp(&h[i], needle, needlelen, /* constfb= */ false, addr) == 0) {
  184             return (void*)(&h[i]);
  185         }
  186     }
  187 
  188     return NULL;
  189 }
  190 
  191 static inline char* HF_strcpy(char* dest, const char* src, uintptr_t addr) {
  192     size_t len = __builtin_strlen(src);
  193     if (len > 0) {
  194         instrumentUpdateCmpMap(addr, util_Log2(len));
  195     }
  196     return __builtin_memcpy(dest, src, len + 1);
  197 }
  198 
  199 /* Define a weak function x, as well as __wrap_x pointing to x */
  200 #define XVAL(x) x
  201 #define HF_WEAK_WRAP(ret, func, ...) \
  202     _Pragma(HF__XSTR(weak func = __wrap_##func)) XVAL(ret) XVAL(__wrap_##func)(__VA_ARGS__)
  203 
  204 /* Typical libc wrappers */
  205 HF_WEAK_WRAP(int, strcmp, const char* s1, const char* s2) {
  206     return HF_strcmp(s1, s2, (uintptr_t)__builtin_return_address(0));
  207 }
  208 void __sanitizer_weak_hook_strcmp(
  209     uintptr_t pc, const char* s1, const char* s2, int result HF_ATTR_UNUSED) {
  210     HF_strcmp(s1, s2, pc);
  211 }
  212 HF_WEAK_WRAP(int, strcasecmp, const char* s1, const char* s2) {
  213     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  214 }
  215 void __sanitizer_weak_hook_strcasecmp(
  216     uintptr_t pc, const char* s1, const char* s2, int result HF_ATTR_UNUSED) {
  217     HF_strcasecmp(s1, s2, tolower, pc);
  218 }
  219 HF_WEAK_WRAP(int, stricmp, const char* s1, const char* s2) {
  220     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  221 }
  222 void __sanitizer_weak_hook_stricmp(
  223     uintptr_t pc, const char* s1, const char* s2, int result HF_ATTR_UNUSED) {
  224     HF_strcasecmp(s1, s2, tolower, pc);
  225 }
  226 HF_WEAK_WRAP(int, strncmp, const char* s1, const char* s2, size_t n) {
  227     return HF_strncmp(s1, s2, n, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  228 }
  229 void __sanitizer_weak_hook_strncmp(
  230     uintptr_t pc, const char* s1, const char* s2, size_t n, int result HF_ATTR_UNUSED) {
  231     HF_strncmp(s1, s2, n, instrumentConstAvail(), pc);
  232 }
  233 HF_WEAK_WRAP(int, strncasecmp, const char* s1, const char* s2, size_t n) {
  234     return HF_strncasecmp(
  235         s1, s2, n, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  236 }
  237 void __sanitizer_weak_hook_strncasecmp(
  238     uintptr_t pc, const char* s1, const char* s2, size_t n, int result HF_ATTR_UNUSED) {
  239     HF_strncasecmp(s1, s2, n, tolower, instrumentConstAvail(), pc);
  240 }
  241 HF_WEAK_WRAP(int, strnicmp, const char* s1, const char* s2, size_t n) {
  242     return HF_strncasecmp(
  243         s1, s2, n, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  244 }
  245 void __sanitizer_weak_hook_strnicmp(
  246     uintptr_t pc, const char* s1, const char* s2, size_t n, int result HF_ATTR_UNUSED) {
  247     HF_strncasecmp(s1, s2, n, tolower, instrumentConstAvail(), pc);
  248 }
  249 HF_WEAK_WRAP(char*, strstr, const char* haystack, const char* needle) {
  250     return HF_strstr(haystack, needle, (uintptr_t)__builtin_return_address(0));
  251 }
  252 void __sanitizer_weak_hook_strstr(
  253     uintptr_t pc, const char* haystack, const char* needle, char* result HF_ATTR_UNUSED) {
  254     HF_strstr(haystack, needle, pc);
  255 }
  256 HF_WEAK_WRAP(char*, strcasestr, const char* haystack, const char* needle) {
  257     return HF_strcasestr(haystack, needle, tolower, (uintptr_t)__builtin_return_address(0));
  258 }
  259 void __sanitizer_weak_hook_strcasestr(
  260     uintptr_t pc, const char* haystack, const char* needle, char* result HF_ATTR_UNUSED) {
  261     HF_strcasestr(haystack, needle, tolower, pc);
  262 }
  263 HF_WEAK_WRAP(int, memcmp, const void* m1, const void* m2, size_t n) {
  264     return HF_memcmp(m1, m2, n, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  265 }
  266 void __sanitizer_weak_hook_memcmp(
  267     uintptr_t pc, const void* m1, const void* m2, size_t n, int result HF_ATTR_UNUSED) {
  268     HF_memcmp(m1, m2, n, instrumentConstAvail(), pc);
  269 }
  270 HF_WEAK_WRAP(int, bcmp, const void* m1, const void* m2, size_t n) {
  271     return HF_memcmp(m1, m2, n, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  272 }
  273 void __sanitizer_weak_hook_bcmp(
  274     uintptr_t pc, const void* m1, const void* m2, size_t n, int result HF_ATTR_UNUSED) {
  275     HF_memcmp(m1, m2, n, instrumentConstAvail(), pc);
  276 }
  277 HF_WEAK_WRAP(
  278     void*, memmem, const void* haystack, size_t haystacklen, const void* needle, size_t needlelen) {
  279     return HF_memmem(
  280         haystack, haystacklen, needle, needlelen, (uintptr_t)__builtin_return_address(0));
  281 }
  282 void __sanitizer_weak_hook_memmem(uintptr_t pc, const void* haystack, size_t haystacklen,
  283     const void* needle, size_t needlelen, void* result HF_ATTR_UNUSED) {
  284     HF_memmem(haystack, haystacklen, needle, needlelen, pc);
  285 }
  286 HF_WEAK_WRAP(char*, strcpy, char* dest, const char* src) {
  287     return HF_strcpy(dest, src, (uintptr_t)__builtin_return_address(0));
  288 }
  289 void __sanitizer_weak_hook_strcpy(
  290     uintptr_t pc, char* dest, const char* src, char* result HF_ATTR_UNUSED) {
  291     HF_strcpy(dest, src, pc);
  292 }
  293 
  294 /*
  295  * Apache's httpd wrappers
  296  */
  297 HF_WEAK_WRAP(int, ap_cstr_casecmp, const char* s1, const char* s2) {
  298     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  299 }
  300 
  301 HF_WEAK_WRAP(int, ap_cstr_casecmpn, const char* s1, const char* s2, size_t n) {
  302     return HF_strncasecmp(
  303         s1, s2, n, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  304 }
  305 
  306 HF_WEAK_WRAP(const char*, ap_strcasestr, const char* s1, const char* s2) {
  307     return HF_strcasestr(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  308 }
  309 
  310 HF_WEAK_WRAP(int, apr_cstr_casecmp, const char* s1, const char* s2) {
  311     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  312 }
  313 
  314 HF_WEAK_WRAP(int, apr_cstr_casecmpn, const char* s1, const char* s2, size_t n) {
  315     return HF_strncasecmp(
  316         s1, s2, n, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  317 }
  318 
  319 /*
  320  * *SSL wrappers
  321  */
  322 HF_WEAK_WRAP(int, CRYPTO_memcmp, const void* m1, const void* m2, size_t len) {
  323     return HF_memcmp(m1, m2, len, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  324 }
  325 
  326 HF_WEAK_WRAP(int, OPENSSL_memcmp, const void* m1, const void* m2, size_t len) {
  327     return HF_memcmp(m1, m2, len, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  328 }
  329 
  330 HF_WEAK_WRAP(int, OPENSSL_strcasecmp, const char* s1, const char* s2) {
  331     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  332 }
  333 
  334 HF_WEAK_WRAP(int, OPENSSL_strncasecmp, const char* s1, const char* s2, size_t len) {
  335     return HF_strncasecmp(
  336         s1, s2, len, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  337 }
  338 
  339 HF_WEAK_WRAP(int32_t, memcmpct, const void* s1, const void* s2, size_t len) {
  340     return HF_memcmp(s1, s2, len, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  341 }
  342 
  343 /*
  344  * libXML wrappers
  345  */
  346 static int xml_to_upper(int c) {
  347     if (c >= 'a' && c <= 'z') {
  348         return c - 'a' + 'A';
  349     }
  350     return c;
  351 }
  352 
  353 HF_WEAK_WRAP(int, xmlStrncmp, const char* s1, const char* s2, int len) {
  354     if (len <= 0) {
  355         return 0;
  356     }
  357     if (s1 == s2) {
  358         return 0;
  359     }
  360     if (s1 == NULL) {
  361         return -1;
  362     }
  363     if (s2 == NULL) {
  364         return 1;
  365     }
  366     return HF_strncmp(
  367         s1, s2, (size_t)len, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  368 }
  369 
  370 HF_WEAK_WRAP(int, xmlStrcmp, const char* s1, const char* s2) {
  371     if (s1 == s2) {
  372         return 0;
  373     }
  374     if (s1 == NULL) {
  375         return -1;
  376     }
  377     if (s2 == NULL) {
  378         return 1;
  379     }
  380     return HF_strcmp(s1, s2, (uintptr_t)__builtin_return_address(0));
  381 }
  382 
  383 HF_WEAK_WRAP(int, xmlStrEqual, const char* s1, const char* s2) {
  384     if (s1 == s2) {
  385         return 1;
  386     }
  387     if (s1 == NULL) {
  388         return 0;
  389     }
  390     if (s2 == NULL) {
  391         return 0;
  392     }
  393     if (HF_strcmp(s1, s2, (uintptr_t)__builtin_return_address(0)) == 0) {
  394         return 1;
  395     }
  396     return 0;
  397 }
  398 
  399 HF_WEAK_WRAP(int, xmlStrcasecmp, const char* s1, const char* s2) {
  400     if (s1 == s2) {
  401         return 0;
  402     }
  403     if (s1 == NULL) {
  404         return -1;
  405     }
  406     if (s2 == NULL) {
  407         return 1;
  408     }
  409     return HF_strcasecmp(s1, s2, xml_to_upper, (uintptr_t)__builtin_return_address(0));
  410 }
  411 
  412 HF_WEAK_WRAP(int, xmlStrncasecmp, const char* s1, const char* s2, int len) {
  413     if (len <= 0) {
  414         return 0;
  415     }
  416     if (s1 == s2) {
  417         return 0;
  418     }
  419     if (s1 == NULL) {
  420         return -1;
  421     }
  422     if (s2 == NULL) {
  423         return 1;
  424     }
  425     return HF_strncasecmp(s1, s2, (size_t)len, xml_to_upper, instrumentConstAvail(),
  426         (uintptr_t)__builtin_return_address(0));
  427 }
  428 
  429 HF_WEAK_WRAP(const char*, xmlStrstr, const char* haystack, const char* needle) {
  430     if (haystack == NULL) {
  431         return NULL;
  432     }
  433     if (needle == NULL) {
  434         return NULL;
  435     }
  436     return HF_strstr(haystack, needle, (uintptr_t)__builtin_return_address(0));
  437 }
  438 
  439 HF_WEAK_WRAP(const char*, xmlStrcasestr, const char* haystack, const char* needle) {
  440     if (haystack == NULL) {
  441         return NULL;
  442     }
  443     if (needle == NULL) {
  444         return NULL;
  445     }
  446     return HF_strcasestr(haystack, needle, xml_to_upper, (uintptr_t)__builtin_return_address(0));
  447 }
  448 
  449 /*
  450  * Samba wrappers
  451  */
  452 HF_WEAK_WRAP(int, memcmp_const_time, const void* s1, const void* s2, size_t n) {
  453     return HF_memcmp(s1, s2, n, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  454 }
  455 
  456 HF_WEAK_WRAP(bool, strcsequal, const void* s1, const void* s2) {
  457     if (s1 == s2) {
  458         return true;
  459     }
  460     if (!s1 || !s2) {
  461         return false;
  462     }
  463     return (HF_strcmp(s1, s2, (uintptr_t)__builtin_return_address(0)) == 0);
  464 }
  465 
  466 /*
  467  * LittleCMS wrappers
  468  */
  469 HF_WEAK_WRAP(int, cmsstrcasecmp, const void* s1, const void* s2) {
  470     return HF_strcasecmp(s1, s2, toupper, (uintptr_t)__builtin_return_address(0));
  471 }
  472 
  473 /*
  474  * GLib wrappers
  475  */
  476 HF_WEAK_WRAP(int, g_strcmp0, const char* s1, const char* s2) {
  477     if (!s1) {
  478         return -(s1 != s2);
  479     }
  480     if (!s2) {
  481         return s1 != s2;
  482     }
  483     return HF_strcmp(s1, s2, (uintptr_t)__builtin_return_address(0));
  484 }
  485 
  486 HF_WEAK_WRAP(int, g_strcasecmp, const char* s1, const char* s2) {
  487     if (!s1 || !s2) {
  488         return 0;
  489     }
  490     return HF_strcasecmp(s1, s2, tolower, (uintptr_t)__builtin_return_address(0));
  491 }
  492 
  493 HF_WEAK_WRAP(int, g_strncasecmp, const char* s1, const char* s2, int n) {
  494     if (!s1 || !s2) {
  495         return 0;
  496     }
  497     return HF_strncasecmp(
  498         s1, s2, n, tolower, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  499 }
  500 
  501 HF_WEAK_WRAP(char*, g_strstr_len, const char* haystack, ssize_t haystack_len, const char* needle) {
  502     if (!haystack || !needle) {
  503         return NULL;
  504     }
  505     if (haystack_len < 0) {
  506         return HF_strstr(haystack, needle, (uintptr_t)__builtin_return_address(0));
  507     }
  508     return HF_memmem(haystack, (size_t)haystack_len, needle, __builtin_strlen(needle),
  509         (uintptr_t)__builtin_return_address(0));
  510 }
  511 
  512 static inline int hf_glib_ascii_tolower(int c) {
  513     if (c >= 'A' && c <= 'Z') {
  514         return c - 'A' + 'a';
  515     }
  516     return c;
  517 }
  518 
  519 HF_WEAK_WRAP(int, g_ascii_strcasecmp, const char* s1, const char* s2) {
  520     if (!s1 || !s2) {
  521         return 0;
  522     }
  523     return HF_strcasecmp(s1, s2, hf_glib_ascii_tolower, (uintptr_t)__builtin_return_address(0));
  524 }
  525 
  526 HF_WEAK_WRAP(int, g_ascii_strncasecmp, const char* s1, const char* s2, size_t n) {
  527     if (!s1 || !s2) {
  528         return 0;
  529     }
  530     return HF_strncasecmp(s1, s2, n, hf_glib_ascii_tolower, instrumentConstAvail(),
  531         (uintptr_t)__builtin_return_address(0));
  532 }
  533 
  534 HF_WEAK_WRAP(bool, g_str_has_prefix, const char* str, const char* prefix) {
  535     if (!str || !prefix) {
  536         return false;
  537     }
  538     return (HF_strncmp(str, prefix, __builtin_strlen(prefix), instrumentConstAvail(),
  539                 (uintptr_t)__builtin_return_address(0)) == 0);
  540 }
  541 
  542 HF_WEAK_WRAP(bool, g_str_has_suffix, const char* str, const char* suffix) {
  543     if (!str || !suffix) {
  544         return false;
  545     }
  546     size_t str_len = __builtin_strlen(str);
  547     size_t suffix_len = __builtin_strlen(suffix);
  548     if (str_len < suffix_len) {
  549         return false;
  550     }
  551 
  552     return (
  553         HF_strcmp(str + str_len - suffix_len, suffix, (uintptr_t)__builtin_return_address(0)) == 0);
  554 }
  555 
  556 /* CUrl wrappers */
  557 static int curl_toupper(int c) {
  558     if (c >= 'a' && c <= 'z') {
  559         return ('A' + c - 'a');
  560     }
  561     return c;
  562 }
  563 
  564 HF_WEAK_WRAP(int, Curl_strcasecompare, const char* first, const char* second) {
  565     if (HF_strcasecmp(first, second, curl_toupper, (uintptr_t)__builtin_return_address(0)) == 0) {
  566         return 1;
  567     }
  568     return 0;
  569 }
  570 
  571 HF_WEAK_WRAP(int, curl_strequal, const char* first, const char* second) {
  572     if (HF_strcasecmp(first, second, curl_toupper, (uintptr_t)__builtin_return_address(0)) == 0) {
  573         return 1;
  574     }
  575     return 0;
  576 }
  577 
  578 HF_WEAK_WRAP(int, Curl_safe_strcasecompare, const char* first, const char* second) {
  579     if (!first && !second) {
  580         return 1;
  581     }
  582     if (!first || !second) {
  583         return 0;
  584     }
  585     if (HF_strcasecmp(first, second, curl_toupper, (uintptr_t)__builtin_return_address(0)) == 0) {
  586         return 1;
  587     }
  588     return 0;
  589 }
  590 
  591 HF_WEAK_WRAP(int, Curl_strncasecompare, const char* first, const char* second, size_t max) {
  592     if (HF_strncasecmp(first, second, max, curl_toupper, instrumentConstAvail(),
  593             (uintptr_t)__builtin_return_address(0)) == 0) {
  594         return 1;
  595     }
  596     return 0;
  597 }
  598 
  599 HF_WEAK_WRAP(int, curl_strnequal, const char* first, const char* second, size_t max) {
  600     if (HF_strncasecmp(first, second, max, curl_toupper, instrumentConstAvail(),
  601             (uintptr_t)__builtin_return_address(0)) == 0) {
  602         return 1;
  603     }
  604     return 0;
  605 }
  606 
  607 /* C++ wrappers */
  608 int _ZNSt11char_traitsIcE7compareEPKcS2_m(const char* s1, const char* s2, size_t count) {
  609     return HF_memcmp(s1, s2, count, instrumentConstAvail(), (uintptr_t)__builtin_return_address(0));
  610 }