-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInformationLoss.ql
More file actions
35 lines (31 loc) · 1.12 KB
/
InformationLoss.ql
File metadata and controls
35 lines (31 loc) · 1.12 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
/**
* @name Implicit narrowing conversion in compound assignment
* @description Compound assignment statements (for example 'intvar += longvar') that implicitly
* cast a value of a wider type to a narrower type may result in information loss and
* numeric errors such as overflows.
* @kind problem
* @problem.severity warning
* @precision very-high
* @id java/implicit-cast-in-compound-assignment
* @tags reliability
* security
* external/cwe/cwe-190
* external/cwe/cwe-192
* external/cwe/cwe-197
* external/cwe/cwe-681
*/
import semmle.code.java.arithmetic.Overflow
class DangerousAssignOpExpr extends AssignOp {
DangerousAssignOpExpr() {
this instanceof AssignAddExpr or
this instanceof AssignMulExpr
}
}
predicate problematicCasting(Type t, Expr e) { e.getType().(NumType).widerThan(t.(NumType)) }
from DangerousAssignOpExpr a, Expr e
where
e = a.getSource() and
problematicCasting(a.getDest().getType(), e)
select a,
"Implicit cast of source type " + e.getType().getName() + " to narrower destination type " +
a.getDest().getType().getName() + "."