Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coolc4 opened this issue Dec 14, 2021 · 1 comment
Open

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

coolc4 opened this issue Dec 14, 2021 · 1 comment

Comments

@coolc4
Copy link

coolc4 commented Dec 14, 2021

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
Copy link
Author

coolc4 commented Dec 14, 2021

And I fixed the bug by th patch:
Uploading curl_escape_memleak_patch.txt…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant