FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/Equality.qll at codeql-cli-2.11.3 · github/codeql · GitHub
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Issues
1k
Pull requests
468
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
/
Equality.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (69 loc) · 2.27 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
Equality.qll
Copy path
File metadata and controls
74 lines (69 loc) · 2.27 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
import
python
private
Attribute
dictAccess
(
LocalVariable
var
)
{
result
.
getName
(
)
=
"__dict__"
and
result
.
getObject
(
)
=
var
.
getAnAccess
(
)
}
private
Call
getattr
(
LocalVariable
obj
,
LocalVariable
attr
)
{
result
.
getFunc
(
)
.
(
Name
)
.
getId
(
)
=
"getattr"
and
result
.
getArg
(
0
)
=
obj
.
getAnAccess
(
)
and
result
.
getArg
(
1
)
=
attr
.
getAnAccess
(
)
}
/**
* A generic equality method that compares all attributes in its dict,
* or compares attributes using `getattr`.
*/
class
GenericEqMethod
extends
Function
{
GenericEqMethod
(
)
{
this
.
getName
(
)
=
"__eq__"
and
exists
(
LocalVariable
self
,
LocalVariable
other
|
self
.
getAnAccess
(
)
=
this
.
getArg
(
0
)
and
self
.
getId
(
)
=
"self"
and
other
.
getAnAccess
(
)
=
this
.
getArg
(
1
)
and
exists
(
Compare
eq
|
eq
.
getOp
(
0
)
instanceof
Eq
or
eq
.
getOp
(
0
)
instanceof
NotEq
|
// `self.__dict__ == other.__dict__`
eq
.
getAChildNode
(
)
=
dictAccess
(
self
)
and
eq
.
getAChildNode
(
)
=
dictAccess
(
other
)
or
// `getattr(self, var) == getattr(other, var)`
exists
(
Variable
var
|
eq
.
getAChildNode
(
)
=
getattr
(
self
,
var
)
and
eq
.
getAChildNode
(
)
=
getattr
(
other
,
var
)
)
)
)
}
}
/** An `__eq__` method that just does `self is other` */
class
IdentityEqMethod
extends
Function
{
IdentityEqMethod
(
)
{
this
.
getName
(
)
=
"__eq__"
and
exists
(
LocalVariable
self
,
LocalVariable
other
|
self
.
getAnAccess
(
)
=
this
.
getArg
(
0
)
and
self
.
getId
(
)
=
"self"
and
other
.
getAnAccess
(
)
=
this
.
getArg
(
1
)
and
exists
(
Compare
eq
|
eq
.
getOp
(
0
)
instanceof
Is
|
eq
.
getAChildNode
(
)
=
self
.
getAnAccess
(
)
and
eq
.
getAChildNode
(
)
=
other
.
getAnAccess
(
)
)
)
}
}
/** An (in)equality method that delegates to its complement */
class
DelegatingEqualityMethod
extends
Function
{
DelegatingEqualityMethod
(
)
{
exists
(
Return
ret
,
UnaryExpr
not_
,
Compare
comp
,
Cmpop
op
,
Parameter
p0
,
Parameter
p1
|
ret
.
getScope
(
)
=
this
and
ret
.
getValue
(
)
=
not_
and
not_
.
getOp
(
)
instanceof
Not
and
not_
.
getOperand
(
)
=
comp
and
comp
.
compares
(
p0
.
getVariable
(
)
.
getAnAccess
(
)
,
op
,
p1
.
getVariable
(
)
.
getAnAccess
(
)
)
|
this
.
getName
(
)
=
"__eq__"
and
op
instanceof
NotEq
or
this
.
getName
(
)
=
"__ne__"
and
op
instanceof
Eq
)
}
}
Back
|
FazBrowse Home
|
New Git URL