FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/src/Critical/GlobalUseBeforeInit.ql at codeql-cli/v2.16.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
998
Pull requests
465
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
/
GlobalUseBeforeInit.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
107 lines (94 loc) · 2.64 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
GlobalUseBeforeInit.ql
Copy path
File metadata and controls
107 lines (94 loc) · 2.64 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @name Global variable may be used before initialization
* @description Using an uninitialized variable may lead to undefined results.
* @kind problem
* @id cpp/global-use-before-init
* @problem.severity warning
* @security-severity 7.8
* @tags reliability
* security
* external/cwe/cwe-457
*/
import
cpp
import
semmle.code.cpp.pointsto.CallGraph
predicate
initFunc
(
GlobalVariable
v
,
Function
f
)
{
exists
(
VariableAccess
access
|
v
.
getAnAccess
(
)
=
access
and
access
.
isUsedAsLValue
(
)
and
access
.
getEnclosingFunction
(
)
=
f
)
}
predicate
useFunc
(
GlobalVariable
v
,
Function
f
)
{
exists
(
VariableAccess
access
|
v
.
getAnAccess
(
)
=
access
and
access
.
isRValue
(
)
and
access
.
getEnclosingFunction
(
)
=
f
)
and
not
initFunc
(
v
,
f
)
}
predicate
uninitialisedBefore
(
GlobalVariable
v
,
Function
f
)
{
f
.
hasGlobalName
(
"main"
)
or
exists
(
Call
call
,
Function
g
|
uninitialisedBefore
(
v
,
g
)
and
call
.
getEnclosingFunction
(
)
=
g
and
(
not
functionInitialises
(
f
,
v
)
or
locallyUninitialisedAt
(
v
,
call
)
)
and
resolvedCall
(
call
,
f
)
)
}
predicate
functionInitialises
(
Function
f
,
GlobalVariable
v
)
{
exists
(
Call
call
|
call
.
getEnclosingFunction
(
)
=
f
and
initialisedBy
(
v
,
call
)
)
}
// this predicate is restricted to global variables used in the
// same function as "call"
predicate
locallyUninitialisedAt
(
GlobalVariable
v
,
Call
call
)
{
functionInitialises
(
call
.
getEnclosingFunction
(
)
,
v
)
and
(
firstCall
(
call
)
or
exists
(
Call
mid
|
locallyUninitialisedAt
(
v
,
mid
)
and
not
initialisedBy
(
v
,
mid
)
and
callPair
(
mid
,
call
)
)
)
}
predicate
initialisedBy
(
GlobalVariable
v
,
Call
call
)
{
exists
(
Function
f
|
resolvedCall
(
call
,
f
)
and
initialises
(
v
,
f
)
)
}
predicate
initialises
(
GlobalVariable
v
,
Function
f
)
{
initFunc
(
v
,
f
)
or
exists
(
Function
mid
|
initialises
(
v
,
mid
)
and
allCalls
(
f
,
mid
)
)
}
predicate
firstCall
(
Call
call
)
{
beforeCall
(
call
)
}
predicate
beforeCall
(
ControlFlowNode
node
)
{
exists
(
Function
f
|
f
.
getBlock
(
)
=
node
)
or
exists
(
ControlFlowNode
mid
|
beforeCall
(
mid
)
and
not
mid
instanceof
Call
and
node
=
mid
.
getASuccessor
(
)
)
}
predicate
callPair
(
Call
call
,
Call
successor
)
{
callReaches
(
call
,
successor
)
}
predicate
callReaches
(
Call
call
,
ControlFlowNode
successor
)
{
call
.
getASuccessor
(
)
=
successor
or
exists
(
ControlFlowNode
mid
|
callReaches
(
call
,
mid
)
and
not
mid
instanceof
Call
and
mid
.
getASuccessor
(
)
=
successor
)
}
from
GlobalVariable
v
,
Function
f
where
uninitialisedBefore
(
v
,
f
)
and
useFunc
(
v
,
f
)
select
f
,
"The variable '"
+
v
.
getName
(
)
+
" is used in this function but may not be initialized when it is called."
Back
|
FazBrowse Home
|
New Git URL