FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/src/Critical/NotInitialised.ql at codeql-cli/v2.19.0 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
997
Pull requests
467
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
NotInitialised.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (72 loc) · 2.29 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
NotInitialised.ql
Copy path
File metadata and controls
81 lines (72 loc) · 2.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* @name Variable not initialized before use
* @description Using an uninitialized variable may lead to undefined results.
* @kind problem
* @id cpp/not-initialised
* @problem.severity error
* @tags reliability
* external/cwe/cwe-457
*/
/*
* See also InitialisationNotRun.ql and GlobalUseBeforeInit.ql
*/
import
cpp
/**
* Holds if `s` defines variable `v` (conservative).
*/
predicate
defines
(
ControlFlowNode
s
,
Variable
lv
)
{
exists
(
VariableAccess
va
|
va
=
s
and
va
.
getTarget
(
)
=
lv
and
va
.
isUsedAsLValue
(
)
)
}
/**
* Holds if `s` uses variable `v` (conservative).
*/
predicate
uses
(
ControlFlowNode
s
,
Variable
lv
)
{
exists
(
VariableAccess
va
|
va
=
s
and
va
.
getTarget
(
)
=
lv
and
va
.
isRValue
(
)
and
not
va
.
getParent
+
(
)
instanceof
SizeofOperator
)
}
/**
* Holds if there is a path from the declaration of `lv` to `n` such that `lv` is
* definitely not defined before `n`.
*/
predicate
noDefPath
(
LocalVariable
lv
,
ControlFlowNode
n
)
{
n
.
(
DeclStmt
)
.
getADeclaration
(
)
=
lv
and
not
exists
(
lv
.
getInitializer
(
)
)
or
exists
(
ControlFlowNode
p
|
noDefPath
(
lv
,
p
)
and
n
=
p
.
getASuccessor
(
)
and
not
defines
(
p
,
lv
)
)
}
predicate
isAggregateType
(
Type
t
)
{
t
instanceof
Class
or
t
instanceof
ArrayType
}
/**
* Holds if `va` is a use of a local variable that has not been previously
* defined.
*/
predicate
undefinedLocalUse
(
VariableAccess
va
)
{
exists
(
LocalVariable
lv
|
// it is hard to tell when a struct or array has been initialized, so we
// ignore them
not
isAggregateType
(
lv
.
getUnderlyingType
(
)
)
and
not
lv
.
isStatic
(
)
and
// static variables are initialized to zero or null by default
not
lv
.
getType
(
)
.
hasName
(
"va_list"
)
and
va
=
lv
.
getAnAccess
(
)
and
noDefPath
(
lv
,
va
)
and
uses
(
va
,
lv
)
)
}
/**
* Holds if `gv` is a potentially uninitialized global variable.
*/
predicate
uninitialisedGlobal
(
GlobalVariable
gv
)
{
exists
(
VariableAccess
va
|
not
isAggregateType
(
gv
.
getUnderlyingType
(
)
)
and
va
=
gv
.
getAnAccess
(
)
and
va
.
isRValue
(
)
and
not
gv
.
hasInitializer
(
)
and
not
gv
.
hasSpecifier
(
"extern"
)
and
not
gv
.
isStatic
(
)
// static variables are initialized to zero or null by default
)
}
from
Element
elt
where
undefinedLocalUse
(
elt
)
or
uninitialisedGlobal
(
elt
)
select
elt
,
"Variable '"
+
elt
.
toString
(
)
+
"' is not initialized."
Back
|
FazBrowse Home
|
New Git URL