ComodoSecurity / openedr

Open EDR public repository
Other
2.3k stars 452 forks source link

Bug:An exception branch handling may cause a memory leak #25

Open coolc4 opened 2 years ago

coolc4 commented 2 years ago

edrav2/eprj/curl/lib/escape.c

char curl_easy_escape(struct Curl_easy data, const char *string, int inlength) { ....

alloc = (inlength?(size_t)inlength:strlen(string)) + 1; newlen = alloc;

//malloc the ns memery ns = malloc(alloc); if(!ns) return NULL; //malloc ok

length = alloc-1; while(length--) { unsigned char in = string; / we need to treat the characters unsigned */

if(Curl_isunreserved(in))
  /* just copy this */
  ns[strindex++] = in;
else {
  /* encode it */
  newlen += 2; /* the size grows with two, since this'll become a %XX */
  if(newlen > alloc) {
    alloc *= 2;
    testing_ptr = Curl_saferealloc(ns, alloc);
    if(!testing_ptr)
      return NULL;
      // Here  will cause the memery leak.

.....

}

coolc4 commented 2 years ago

And I fixed the bug by th patch: [Uploading curl_escape_memleak_patch.txt…]()