FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/src/Critical/LoopBounds.qll at codeql-cli/v2.19.2 · 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
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
/
LoopBounds.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (58 loc) · 1.78 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
LoopBounds.qll
Copy path
File metadata and controls
66 lines (58 loc) · 1.78 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
/** Provides helpers for OverflowStatic.ql */
import
cpp
/**
* An assignment to a variable with the value `0`. For example:
* ```
* int x;
* x = 0;
* ```
* but not:
* ```
* int x = 0;
* ```
*/
class
ZeroAssignment
extends
AssignExpr
{
ZeroAssignment
(
)
{
this
.
getAnOperand
(
)
instanceof
VariableAccess
and
this
.
getAnOperand
(
)
instanceof
Zero
}
/** Gets a variable that is assigned the value `0`. */
Variable
assignedVariable
(
)
{
result
.
getAnAccess
(
)
=
this
.
getAnOperand
(
)
}
}
private
predicate
staticLimit
(
RelationalOperation
op
,
Variable
v
,
int
limit
)
{
op
instanceof
LTExpr
and
op
.
getLeftOperand
(
)
=
v
.
getAnAccess
(
)
and
op
.
getRightOperand
(
)
.
getValue
(
)
.
toInt
(
)
-
1
=
limit
or
op
instanceof
LEExpr
and
op
.
getLeftOperand
(
)
=
v
.
getAnAccess
(
)
and
op
.
getRightOperand
(
)
.
getValue
(
)
.
toInt
(
)
=
limit
}
private
predicate
simpleInc
(
IncrementOperation
inc
,
Variable
v
)
{
inc
.
getAChild
(
)
=
v
.
getAnAccess
(
)
}
/**
* A `for` loop of the form `for (x = 0; x < limit; x++)` with no modification
* of `x` in the body. Variations with `<=` and `++x` are allowed.
*/
class
ClassicForLoop
extends
ForStmt
{
ClassicForLoop
(
)
{
exists
(
LocalVariable
v
|
this
.
getInitialization
(
)
.
getAChild
(
)
instanceof
ZeroAssignment
and
staticLimit
(
this
.
getCondition
(
)
,
v
,
_
)
and
simpleInc
(
this
.
getUpdate
(
)
,
v
)
and
not
exists
(
VariableAccess
access
|
access
.
isUsedAsLValue
(
)
and
v
.
getAnAccess
(
)
=
access
and
this
.
getStmt
(
)
.
getAChild
*
(
)
=
access
.
getEnclosingStmt
(
)
)
)
}
/** Gets the loop variable. */
LocalVariable
counter
(
)
{
simpleInc
(
this
.
getUpdate
(
)
,
result
)
}
/**
* Gets the maximum value that the loop variable may have inside the loop
* body. The minimum is 0.
*/
int
limit
(
)
{
staticLimit
(
this
.
getCondition
(
)
,
_
,
result
)
}
}
Back
|
FazBrowse Home
|
New Git URL