FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/src/Critical/ScanfChecks.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
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
/
ScanfChecks.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (59 loc) · 1.9 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
src
/
Critical
/
ScanfChecks.qll
Copy path
File metadata and controls
64 lines (59 loc) · 1.9 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
private
import
cpp
private
import
semmle.code.cpp.commons.Scanf
private
import
semmle.code.cpp.controlflow.IRGuards
private
import
semmle.code.cpp.ir.ValueNumbering
private
predicate
exprInBooleanContext
(
Expr
e
)
{
exists
(
IRGuardCondition
gc
|
exists
(
Instruction
i
|
i
.
getUnconvertedResultExpression
(
)
=
e
and
gc
.
comparesEq
(
valueNumber
(
i
)
.
getAUse
(
)
,
0
,
_
,
_
)
)
or
gc
.
getUnconvertedResultExpression
(
)
=
e
)
}
private
predicate
isLinuxKernel
(
)
{
// For the purpose of sscanf, we check the header guards for the files that it is defined in (which have changed)
exists
(
Macro
macro
|
macro
.
getName
(
)
in
[
"_LINUX_KERNEL_SPRINTF_H_"
,
"_LINUX_KERNEL_H"
]
)
}
/**
* Gets the value of the EOF macro.
*
* This is typically `"-1"`, but this is not guaranteed to be the case on all
* systems.
*/
private
string
getEofValue
(
)
{
exists
(
MacroInvocation
mi
|
mi
.
getMacroName
(
)
=
"EOF"
and
result
=
unique
(
|
|
mi
.
getExpr
(
)
.
getValue
(
)
)
)
}
/**
* Holds if the value of `call` has been checked to not equal `EOF`.
*/
private
predicate
checkedForEof
(
ScanfFunctionCall
call
)
{
exists
(
IRGuardCondition
gc
|
exists
(
Instruction
i
|
i
.
getUnconvertedResultExpression
(
)
=
call
|
exists
(
int
val
|
gc
.
comparesEq
(
valueNumber
(
i
)
.
getAUse
(
)
,
val
,
_
,
_
)
|
// call == EOF
val
=
getEofValue
(
)
.
toInt
(
)
or
// call == [any positive number]
val
>
0
)
or
exists
(
int
val
|
gc
.
comparesLt
(
valueNumber
(
i
)
.
getAUse
(
)
,
val
,
true
,
_
)
|
// call < [any non-negative number] (EOF is guaranteed to be negative)
val
>=
0
)
)
)
}
/**
* Holds if `call` is a `scanf`-like call were the result is only checked against 0, but it can also return EOF.
*/
predicate
incorrectlyCheckedScanf
(
ScanfFunctionCall
call
)
{
exprInBooleanContext
(
call
)
and
not
checkedForEof
(
call
)
and
not
isLinuxKernel
(
)
// scanf in the linux kernel can't return EOF
}
Back
|
FazBrowse Home
|
New Git URL