FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/MethodCallOrder.qll at codeql-cli/v2.15.5 · 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
460
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
/
python
/
ql
/
src
/
Classes
/
MethodCallOrder.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (68 loc) · 2.76 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
MethodCallOrder.qll
Copy path
File metadata and controls
75 lines (68 loc) · 2.76 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
import
python
// Helper predicates for multiple call to __init__/__del__ queries.
pragma
[
noinline
]
private
predicate
multiple_invocation_paths_helper
(
FunctionInvocation
top
,
FunctionInvocation
i1
,
FunctionInvocation
i2
,
FunctionObject
multi
)
{
i1
!=
i2
and
i1
=
top
.
getACallee
+
(
)
and
i2
=
top
.
getACallee
+
(
)
and
i1
.
getFunction
(
)
=
multi
}
pragma
[
noinline
]
private
predicate
multiple_invocation_paths
(
FunctionInvocation
top
,
FunctionInvocation
i1
,
FunctionInvocation
i2
,
FunctionObject
multi
)
{
multiple_invocation_paths_helper
(
top
,
i1
,
i2
,
multi
)
and
i2
.
getFunction
(
)
=
multi
}
/** Holds if `self.name` calls `multi` by multiple paths, and thus calls it more than once. */
predicate
multiple_calls_to_superclass_method
(
ClassObject
self
,
FunctionObject
multi
,
string
name
)
{
exists
(
FunctionInvocation
top
,
FunctionInvocation
i1
,
FunctionInvocation
i2
|
multiple_invocation_paths
(
top
,
i1
,
i2
,
multi
)
and
top
.
runtime
(
self
.
declaredAttribute
(
name
)
)
and
self
.
getASuperType
(
)
.
declaredAttribute
(
name
)
=
multi
|
// Only called twice if called from different functions,
// or if one call-site can reach the other.
i1
.
getCall
(
)
.
getScope
(
)
!=
i2
.
getCall
(
)
.
getScope
(
)
or
i1
.
getCall
(
)
.
strictlyReaches
(
i2
.
getCall
(
)
)
)
}
/** Holds if all attributes called `name` can be inferred to be methods. */
private
predicate
named_attributes_not_method
(
ClassObject
cls
,
string
name
)
{
cls
.
declaresAttribute
(
name
)
and
not
cls
.
declaredAttribute
(
name
)
instanceof
FunctionObject
}
/** Holds if `f` actually does something. */
private
predicate
does_something
(
FunctionObject
f
)
{
f
.
isBuiltin
(
)
and
not
f
=
theObjectType
(
)
.
lookupAttribute
(
"__init__"
)
or
exists
(
Stmt
s
|
s
=
f
.
getFunction
(
)
.
getAStmt
(
)
and
not
s
instanceof
Pass
)
}
/** Holds if `meth` looks like it should have a call to `name`, but does not */
private
predicate
missing_call
(
FunctionObject
meth
,
string
name
)
{
exists
(
CallNode
call
,
AttrNode
attr
|
call
.
getScope
(
)
=
meth
.
getFunction
(
)
and
call
.
getFunction
(
)
=
attr
and
attr
.
getName
(
)
=
name
and
not
exists
(
FunctionObject
f
|
f
.
getACall
(
)
=
call
)
)
}
/** Holds if `self.name` does not call `missing`, even though it is expected to. */
predicate
missing_call_to_superclass_method
(
ClassObject
self
,
FunctionObject
top
,
FunctionObject
missing
,
string
name
)
{
missing
=
self
.
getASuperType
(
)
.
declaredAttribute
(
name
)
and
top
=
self
.
lookupAttribute
(
name
)
and
/* There is no call to missing originating from top */
not
top
.
getACallee
*
(
)
=
missing
and
/* Make sure that all named 'methods' are objects that we can understand. */
not
exists
(
ClassObject
sup
|
sup
=
self
.
getAnImproperSuperType
(
)
and
named_attributes_not_method
(
sup
,
name
)
)
and
not
self
.
isAbstract
(
)
and
does_something
(
missing
)
and
not
missing_call
(
top
,
name
)
}
Back
|
FazBrowse Home
|
New Git URL