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

MEDIUM: Potentially Unsafe Code - Potential Memory Leak #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DawmosTomie
Copy link

Dear author, Hello!
I found a small security breach,
I've modified it,
I hope you can merge it。
(My English is not very good, I hope the wording does not offend you)

Description-MEDIUM: Potentially Unsafe Code - Potential Memory Leak

Line: 71 - Dependencies\third_party\phlib\jsonc\arraylist.c
Source code may experience memory leaks when attempting to extend arrays.
If the realloc function fails and returns NULL, the original memory is still retained.

Solution

solve this problem by checking the return value of realloc after calling it.
If realloc returns NULL, the original memory should be freed and an error returned.

Modified code

{
  void *t;
  int new_size;

  if(max < arr->size) return 0;
  new_size = json_max(arr->size << 1, max);
  t = realloc(arr->array, new_size*sizeof(void*));
  if(!t) {
    free(arr->array);
    return -1;
  }
  arr->array = (void**)t;
  (void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
  arr->size = new_size;
  return 0;
}```


  
 

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

Successfully merging this pull request may close these issues.

None yet

1 participant