-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathUseAfterFreeSolution.ql
More file actions
36 lines (28 loc) · 920 Bytes
/
UseAfterFreeSolution.ql
File metadata and controls
36 lines (28 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @name Use after free
* @kind path-problem
* @id cpp/workshop/use-after-free
*/
import cpp
import semmle.code.cpp.dataflow.TaintTracking
import DataFlow::PathGraph
class Config extends DataFlow::Configuration {
Config() { this = "Use after free config (doesn't matter)"}
override predicate isSource(DataFlow::Node arg) {
exists(FunctionCall call |
call.getArgument(0) = arg.asDefiningArgument() and
call.getTarget().hasGlobalOrStdName("free")
)
}
override predicate isSink(DataFlow::Node sink) {
dereferenced(sink.asExpr()) // depends on DataFlow1
}
override predicate isBarrier(DataFlow::Node barrier) {
none()
}
}
from DataFlow::PathNode source, DataFlow::PathNode sink, Config config
where config.hasFlowPath(source, sink)
select sink, source, sink,
"Potential use-after-free vulnerability: memory is $@ and $@.",
source, "freed here", sink, "used here"