I am trying to track errors after using in C. And my question is if I have code like this:
A * ptrA = malloc(sizeof(A)); A * aliasA = ptrA;
Just wondering if using aliasA is UAF error? If so, what is going wrong here?
To fix this question, I think itβs better to add a small example:
int main(){ int *ptr = (int *)malloc(4); *ptr = 5; int *ptr2 = ptr; printf("%d\n", *ptr); free(ptr); int *new_ptr = malloc(4); *new_ptr = 66; printf("%d\n", *ptr2); return 0; }
And the result:
5 66
(I checked ptr and new_ptr in S2E: http://s2e.systems/ , and these two pointers actually point to the same address. After releasing ptr, the same address is assigned to new_ptr.)
From the above output, it seems that using ptr2 gives the same result as new_ptr .
When I wrote my solution for detecting a UAF error, I write down the pointer information. Pointer values ββare stored as uint64_t , and the boolean type flag is used to declare whether the pointer is alive.
Therefore, I assume that the problem occurs when the new_ptr and ptr tags point to the same address, because once malloc() is called flag new_ptr will turn true . After that, when I use ptr , I can not detect this UAF error, because this address is marked as live.
Thanks in advance!
source share