-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathUninitializedLocal.ql
36 lines (33 loc) · 1.01 KB
/
UninitializedLocal.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
/**
* @name Potentially uninitialized local variable
* @description Using a local variable before it is initialized gives the variable a default
* 'nil' value.
* @kind problem
* @problem.severity error
* @id rb/uninitialized-local-variable
* @tags reliability
* correctness
* @precision low
*/
import codeql.ruby.AST
import codeql.ruby.dataflow.SSA
class RelevantLocalVariableReadAccess extends LocalVariableReadAccess {
RelevantLocalVariableReadAccess() {
not exists(MethodCall c |
c.getReceiver() = this and
c.getMethodName() = "nil?"
) and
not exists(BinaryOperation b |
b.getLeftOperand() = this and
b.getOperator() = "||"
)
}
}
from RelevantLocalVariableReadAccess read, LocalVariable v
where
v = read.getVariable() and
exists(Ssa::Definition def |
def.getAnUltimateDefinition() instanceof Ssa::UninitializedDefinition and
read = def.getARead().getExpr()
)
select read, "Local variable $@ may be used before it is initialized.", v, v.getName()