-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathArithmeticUncontrolled.ql
More file actions
59 lines (48 loc) · 2.11 KB
/
ArithmeticUncontrolled.ql
File metadata and controls
59 lines (48 loc) · 2.11 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @name Uncontrolled data in arithmetic expression
* @description Arithmetic operations on uncontrolled data that is not validated can cause
* overflows.
* @kind path-problem
* @problem.severity warning
* @security-severity 8.6
* @precision medium
* @id java/uncontrolled-arithmetic
* @tags security
* external/cwe/cwe-190
* external/cwe/cwe-191
*/
import java
import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.security.Random
import semmle.code.java.security.SecurityTests
import ArithmeticCommon
import DataFlow::PathGraph
class TaintSource extends DataFlow::ExprNode {
TaintSource() {
exists(RandomDataSource m | not m.resultMayBeBounded() | m.getOutput() = this.getExpr())
}
}
class ArithmeticUncontrolledOverflowConfig extends TaintTracking::Configuration {
ArithmeticUncontrolledOverflowConfig() { this = "ArithmeticUncontrolledOverflowConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof TaintSource }
override predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
override predicate isSanitizer(DataFlow::Node n) { overflowBarrier(n) }
}
class ArithmeticUncontrolledUnderflowConfig extends TaintTracking::Configuration {
ArithmeticUncontrolledUnderflowConfig() { this = "ArithmeticUncontrolledUnderflowConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof TaintSource }
override predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
override predicate isSanitizer(DataFlow::Node n) { underflowBarrier(n) }
}
from DataFlow::PathNode source, DataFlow::PathNode sink, ArithExpr exp, string effect
where
any(ArithmeticUncontrolledOverflowConfig c).hasFlowPath(source, sink) and
overflowSink(exp, sink.getNode().asExpr()) and
effect = "overflow"
or
any(ArithmeticUncontrolledUnderflowConfig c).hasFlowPath(source, sink) and
underflowSink(exp, sink.getNode().asExpr()) and
effect = "underflow"
select exp, source, sink,
"$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".",
source.getNode(), "Uncontrolled value"