You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(* If we're single-threaded or there are no threads freeing the memory, we have nothing to WARN about *)
33
+
if ctx.ask (Queries.MustBeSingleThreaded { since_start =true }) ||ThreadIdSet.is_empty freeing_threads then()
34
+
elsebegin
35
+
letpossibly_startedcurrent=function
36
+
|`Liftedtid ->
37
+
let threads = ctx.ask Queries.CreatedThreadsin
38
+
let not_started =MHP.definitely_not_started (current, threads) tid in
39
+
let possibly_started =not not_started in
40
+
possibly_started
41
+
|`Top -> true
42
+
|`Bot -> false
43
+
in
44
+
letequal_currentcurrent=function
45
+
|`Liftedtid ->
46
+
ThreadId.Thread.equal current tid
47
+
|`Top -> true
48
+
|`Bot -> false
49
+
in
50
+
match get_current_threadid ctx with
51
+
|`Liftedcurrent ->
52
+
let possibly_started =ThreadIdSet.exists (possibly_started current) freeing_threads in
53
+
if possibly_started then
54
+
M.warn ~category:(Behavior behavior) ~tags:[CWE cwe_number] "There's a thread that's been started in parallel with the memory-freeing threads for heap variable %a. Use-After-Free might occur"CilType.Varinfo.pretty heap_var
55
+
elsebegin
56
+
let current_is_unique =ThreadId.Thread.is_unique current in
57
+
letany_equal_currentthreads=ThreadIdSet.exists (equal_current current) threads in
58
+
ifnot current_is_unique && any_equal_current freeing_threads then
59
+
M.warn ~category:(Behavior behavior) ~tags:[CWE cwe_number] "Current thread is not unique and a Use-After-Free might occur for heap variable %a"CilType.Varinfo.pretty heap_var
60
+
elseifD.mem heap_var ctx.local then
61
+
M.warn ~category:(Behavior behavior) ~tags:[CWE cwe_number] "Use-After-Free might occur in current unique thread %a for heap variable %a"ThreadIdDomain.FlagConfiguredTID.pretty current CilType.Varinfo.pretty heap_var
62
+
end
63
+
|`Top ->
64
+
M.warn ~category:(Behavior behavior) ~tags:[CWE cwe_number] "CurrentThreadId is top. A Use-After-Free might occur for heap variable %a"CilType.Varinfo.pretty heap_var
65
+
|`Bot ->
66
+
M.warn ~category:MessageCategory.Analyzer"CurrentThreadId is bottom"
0 commit comments