forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBadAbsOfRandom.ql
More file actions
26 lines (24 loc) · 879 Bytes
/
BadAbsOfRandom.ql
File metadata and controls
26 lines (24 loc) · 879 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
/**
* @name Incorrect absolute value of random number
* @description Calling 'Math.abs' to find the absolute value of a randomly generated integer is not
* guaranteed to return a non-negative integer.
* @kind problem
* @problem.severity warning
* @precision medium
* @id java/abs-of-random
* @suites security-and-quality
* @tags reliability
* maintainability
*/
import java
import semmle.code.java.security.RandomQuery
from MethodCall ma, Method abs, Method nextIntOrLong, RandomDataSource nma
where
ma.getMethod() = abs and
abs.hasName("abs") and
abs.getDeclaringType().hasQualifiedName("java.lang", "Math") and
ma.getAnArgument() = nma and
nma.getMethod() = nextIntOrLong and
nextIntOrLong.hasName(["nextInt", "nextLong"]) and
not nma.resultMayBeBounded()
select ma, "Incorrect computation of abs of signed integral random value."