-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for UAF in multi-threaded context
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
tests/regression/71-use_after_free/12-multi-threaded-uaf.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//PARAM: --set ana.activated[+] useAfterFree | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <pthread.h> | ||
|
||
int* gptr; | ||
|
||
// Mutex to ensure we don't get race warnings, but the UAF warnings we actually care about | ||
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_other(void* p) { | ||
pthread_mutex_lock(&mtx); | ||
free(gptr); //WARN | ||
pthread_mutex_unlock(&mtx); | ||
} | ||
|
||
int main() { | ||
gptr = malloc(sizeof(int)); | ||
*gptr = 42; | ||
|
||
pthread_t thread; | ||
pthread_create(&thread, NULL, t_other, NULL); | ||
|
||
pthread_mutex_lock(&mtx); | ||
*gptr = 43; //WARN | ||
free(gptr); //WARN | ||
pthread_mutex_unlock(&mtx); | ||
|
||
return 0; | ||
} |