Skip to content

Commit 21ce54b

Browse files
author
eternalsakura
committed
[fix] refactor
1 parent 80f7e21 commit 21ce54b

4 files changed

Lines changed: 127 additions & 139 deletions

File tree

CodeQL_Queries/cpp/Chrome/object_lifetime/lifetime_management.qll

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ import cpp
22
import callbacks
33

44
/**
5-
* Models various mechanism in Chrome that is used for managing object lifetime.
5+
* A map field that has pointer as key and managed pointer of the same type as value.
6+
* Usually the value are backing the keys, so it is usually ok.
67
*/
7-
8-
/**
9-
* A map field that has pointer as key and managed pointer of the same type as value.
10-
* Usually the value are backing the keys, so it is usually ok.
11-
*/
128
class ManagedKeyValueField extends MapField {
139
ManagedKeyValueField() {
1410
exists(PointerType key, ManagedPtr value |
@@ -40,13 +36,9 @@ predicate destructorCleanup(GeneralPointerField f, Destructor d, Expr fa) {
4036
* so raw pointer of rfh inside it is usually ok.
4137
*/
4238
class FrameServiceBase extends ClassTemplateInstantiation {
43-
FrameServiceBase() {
44-
getName().matches("FrameServiceBase<%")
45-
}
46-
47-
Type getService() {
48-
result = getTemplateArgument(0)
49-
}
39+
FrameServiceBase() { getName().matches("FrameServiceBase<%") }
40+
41+
Type getService() { result = getTemplateArgument(0) }
5042
}
5143

5244
predicate frameServiceBaseProtected(Field f) {
@@ -60,13 +52,15 @@ predicate frameServiceBaseProtected(Field f) {
6052
* inside constructor/destructor etc., which usually makes them ok.
6153
*/
6254
predicate notInsideConstructor(Class c, Expr e) {
63-
not exists(Constructor f | f = e.getEnclosingFunction() and
55+
not exists(Constructor f |
56+
f = e.getEnclosingFunction() and
6457
f.getDeclaringType() = c
6558
)
6659
}
6760

6861
predicate notInsideDestructor(Class c, Expr e) {
69-
not exists(Destructor f | f = e.getEnclosingFunction() and
62+
not exists(Destructor f |
63+
f = e.getEnclosingFunction() and
7064
f.getDeclaringType() = c
7165
)
7266
}

CodeQL_Queries/cpp/Chrome/object_lifetime/obj_lifetime.qll

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import pointers.managed_ptr
44
/**
55
* Long live classes, e.g. Singleton, classes owned by BrowserLoop etc.
66
*/
7-
87
class OwnedByBrowserContext extends Class {
98
OwnedByBrowserContext() {
109
this.getName() = "VideoDecodePerfHistory" or
@@ -18,21 +17,30 @@ class OwnedByBrowserContext extends Class {
1817
this.getName() = "DownloadManager" or
1918
this.getName() = "BrowsingDataRemover" or
2019
this.getName() = "PermissionController"
21-
}
20+
}
2221
}
2322

2423
class Singleton extends Type {
2524
Singleton() {
26-
this.hasName("MediaInternals") or
27-
hasName("NetworkConnectionTracker") or
28-
hasName("ChildProcessSecurityPolicyImpl") or
29-
hasName("MprisService") or
30-
hasName("PluginServiceFilter") or
31-
hasName("TickClock") or
32-
exists(Class c | c.getName().matches("Singleton<%") and
25+
this.hasName("MediaInternals")
26+
or
27+
hasName("NetworkConnectionTracker")
28+
or
29+
hasName("ChildProcessSecurityPolicyImpl")
30+
or
31+
hasName("MprisService")
32+
or
33+
hasName("PluginServiceFilter")
34+
or
35+
hasName("TickClock")
36+
or
37+
exists(Class c |
38+
c.getName().matches("Singleton<%") and
3339
this = c.getTemplateArgument(0)
34-
) or
35-
exists(Variable v | v.isStatic() and
40+
)
41+
or
42+
exists(Variable v |
43+
v.isStatic() and
3644
v.getType().getName().matches("NoDestructor<%") and
3745
v.getType().(Class).getTemplateArgument(0) = this and
3846
not this.getName().matches("vector<%") and
@@ -58,11 +66,15 @@ class Singleton extends Type {
5866
*/
5967
class OwnedByBrowserMainLoop extends Class {
6068
OwnedByBrowserMainLoop() {
61-
exists(GeneralManagedField f | f.getManagedType() = this and
69+
exists(GeneralManagedField f |
70+
f.getManagedType() = this and
6271
f.getDeclaringType().hasName("BrowserMainLoop")
63-
) or
64-
getName() = "UserInputMonitor" or
65-
getName() = "UserInputMonitorBase" or
72+
)
73+
or
74+
getName() = "UserInputMonitor"
75+
or
76+
getName() = "UserInputMonitorBase"
77+
or
6678
getName() = "BrowserGpuChannelHostFactory"
6779
}
6880
}

0 commit comments

Comments
 (0)