-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathArithmeticUncontrolled.ql
38 lines (34 loc) · 1.36 KB
/
ArithmeticUncontrolled.ql
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
/**
* @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.DataFlow
import semmle.code.java.security.ArithmeticCommon
import semmle.code.java.security.ArithmeticUncontrolledQuery
module Flow =
DataFlow::MergePathGraph<ArithmeticUncontrolledOverflowFlow::PathNode,
ArithmeticUncontrolledUnderflowFlow::PathNode, ArithmeticUncontrolledOverflowFlow::PathGraph,
ArithmeticUncontrolledUnderflowFlow::PathGraph>;
import Flow::PathGraph
from Flow::PathNode source, Flow::PathNode sink, ArithExpr exp, string effect
where
ArithmeticUncontrolledOverflowFlow::flowPath(source.asPathNode1(), sink.asPathNode1()) and
overflowSink(exp, sink.getNode().asExpr()) and
effect = "overflow"
or
ArithmeticUncontrolledUnderflowFlow::flowPath(source.asPathNode2(), sink.asPathNode2()) and
underflowSink(exp, sink.getNode().asExpr()) and
effect = "underflow"
select exp, source, sink,
"This arithmetic expression depends on an $@, potentially causing an " + effect + ".",
source.getNode(), "uncontrolled value"