Skip to content

Commit 80f7e21

Browse files
author
eternalsakura
committed
[fix] refactor
1 parent 7917c18 commit 80f7e21

6 files changed

Lines changed: 311 additions & 325 deletions

File tree

CodeQL_Queries/cpp/Chrome/bindings.qll

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,46 @@ import common
44
/**
55
* Library for mojo bindings.
66
*/
7-
87
class StrongBinding extends ClassTemplateInstantiation {
9-
StrongBinding() {
10-
getName().matches("StrongBinding%")
11-
}
12-
13-
Type getBindingType() {
14-
result = this.getTemplateArgument(0).(Type).stripType()
15-
}
8+
StrongBinding() { getName().matches("StrongBinding%") }
9+
10+
Type getBindingType() { result = this.getTemplateArgument(0).(Type).stripType() }
1611
}
1712

1813
class Binding extends ClassTemplateInstantiation {
19-
Binding() {
20-
getName().matches("Binding<%")
21-
}
22-
23-
Type getBindingType() {
24-
result = this.getTemplateArgument(0).(Type).stripType()
25-
}
26-
}
14+
Binding() { getName().matches("Binding<%") }
2715

16+
Type getBindingType() { result = this.getTemplateArgument(0).(Type).stripType() }
17+
}
2818

2919
class MojoReceiver extends ClassTemplateInstantiation {
30-
MojoReceiver() {
31-
getQualifiedName().matches("%mojo::Receiver<%")
32-
}
33-
34-
Type getBindingType() {
35-
result = this.getTemplateArgument(0).(Type).stripType()
36-
}
20+
MojoReceiver() { getQualifiedName().matches("%mojo::Receiver<%") }
21+
22+
Type getBindingType() { result = this.getTemplateArgument(0).(Type).stripType() }
3723
}
3824

3925
class InterfaceBinding extends Class {
4026
FunctionCall addBinding;
41-
27+
4228
InterfaceBinding() {
4329
addBinding.getTarget().hasName("AddBinding") and
4430
this = generalStripType(addBinding.getArgument(0).getAChild*().getType())
4531
}
46-
47-
FunctionCall getABinding() {
48-
result = addBinding
49-
}
32+
33+
FunctionCall getABinding() { result = addBinding }
5034
}
5135

5236
class InterfacePtr extends ClassTemplateInstantiation {
5337
InterfacePtr() {
5438
stripType().getName().matches("InterfacePtr<%") or
5539
stripType().getName().matches("InterfacePtrInfo<%")
5640
}
57-
58-
Type getInterfaceType() {
59-
result = getTemplateArgument(0)
60-
}
61-
41+
42+
Type getInterfaceType() { result = getTemplateArgument(0) }
43+
6244
Type getInterfacePtrType() {
63-
exists(string s | s = getInterfaceType().getName() + "Ptr" and
45+
exists(string s |
46+
s = getInterfaceType().getName() + "Ptr" and
6447
result.getName() = s
6548
)
6649
}
@@ -81,19 +64,18 @@ class StructPtr extends Class {
8164
getName().matches("StructPtr<%") or
8265
getName().matches("InlinedStructPtr<%")
8366
}
84-
85-
Type getStructType() {
86-
result = getTemplateArgument(0)
87-
}
67+
68+
Type getStructType() { result = getTemplateArgument(0) }
8869
}
8970

9071
Type stripStructPtrType(Type c) {
91-
(
92-
c.getName().matches("vector<%") and
93-
result = stripStructPtrType(c.(Class).getTemplateArgument(0))
94-
) or
95-
exists(StructPtr t | t = c.stripType() and
72+
c.getName().matches("vector<%") and
73+
result = stripStructPtrType(c.(Class).getTemplateArgument(0))
74+
or
75+
exists(StructPtr t |
76+
t = c.stripType() and
9677
result = t.getStructType().stripType()
97-
) or
78+
)
79+
or
9880
result = c.stripType()
9981
}

CodeQL_Queries/cpp/Chrome/callback_tracking.qll

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import bindings
44
import field
55
import callbacks
66

7-
/**
8-
* Dataflow library for tracking unretained or retained types in a callback.
9-
*/
10-
117
/**
128
* An assignment to a callback field.
139
*/
@@ -26,26 +22,30 @@ predicate runCallbackSink(DataFlow::Node sink) {
2622
* An expression that posts a callback to a task runner.
2723
*/
2824
predicate postTaskSink(DataFlow::Node sink) {
29-
exists(FunctionCall postTask | postTask.getTarget().getName().matches("PostTask%") or
30-
postTask.getTarget().getName() = "PostDelayedTask" |
25+
exists(FunctionCall postTask |
26+
postTask.getTarget().getName().matches("PostTask%") or
27+
postTask.getTarget().getName() = "PostDelayedTask"
28+
|
3129
postTask.getAnArgument() = sink.asExpr()
3230
)
3331
}
3432

3533
/**
3634
* Callback gets passed inside an interface pointer function. The idea is that such a
37-
* callback may then be called from the renderer. (A bit like
35+
* callback may then be called from the renderer. (A bit like
3836
* https://bugs.chromium.org/p/project-zero/issues/detail?id=1755
3937
* )
4038
*/
4139
predicate interfacePtrCallSink(DataFlow::Node sink) {
42-
exists(FunctionCall mojom, InterfacePtr iPtr, Function interfaceFunc |
40+
exists(FunctionCall mojom, InterfacePtr iPtr, Function interfaceFunc |
4341
overrides*(mojom.getTarget(), interfaceFunc) and
4442
interfaceFunc.getDeclaringType() = iPtr.getInterfaceType() and
4543
sink.asExpr() = mojom.getAnArgument()
46-
) or
47-
exists(BindCall bc, InterfacePtr iPtr, Function interfaceFunc |
48-
overrides*(bc.getFunction(), interfaceFunc) and interfaceFunc.getDeclaringType() = iPtr.getInterfaceType() and
44+
)
45+
or
46+
exists(BindCall bc, InterfacePtr iPtr, Function interfaceFunc |
47+
overrides*(bc.getFunction(), interfaceFunc) and
48+
interfaceFunc.getDeclaringType() = iPtr.getInterfaceType() and
4949
sink.asExpr() = bc.getAnArgument() and
5050
sink.asExpr() != bc.getArgument(0)
5151
)
@@ -59,25 +59,20 @@ predicate callbackArgSink(DataFlow::Node sink) {
5959
}
6060

6161
class CallbackConfig extends DataFlow::Configuration {
62-
CallbackConfig() {
63-
this = "callbackconfig"
64-
}
65-
62+
CallbackConfig() { this = "callbackconfig" }
63+
6664
override predicate isSource(DataFlow::Node source) {
6765
(
68-
exists(GeneralCallback fc |
69-
source.asExpr() = fc
70-
)
66+
exists(GeneralCallback fc | source.asExpr() = fc)
7167
or
7268
exists(CallbackField f | source.asExpr() = f.getAnAccess())
73-
)
74-
and
69+
) and
7570
not source.asExpr().getFile().getBaseName() = "bind.h" and
76-
not source.asExpr().getFile().getBaseName() = "callback_helpers.h"// and
71+
not source.asExpr().getFile().getBaseName() = "callback_helpers.h" // and
7772
}
78-
73+
7974
override predicate isSink(DataFlow::Node sink) {
80-
(
75+
(
8176
isCallbackFieldSink(sink)
8277
or
8378
runCallbackSink(sink)
@@ -87,7 +82,7 @@ class CallbackConfig extends DataFlow::Configuration {
8782
interfacePtrCallSink(sink)
8883
or
8984
callbackArgSink(sink)
90-
) and
85+
) and
9186
(
9287
//Exclude sinks that are in uninteresting files.
9388
not sink.asExpr().getFile().getBaseName() = "bind_internal.h" and
@@ -103,15 +98,21 @@ class CallbackConfig extends DataFlow::Configuration {
10398
sink.asExpr().fromSource()
10499
)
105100
}
106-
101+
107102
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
108-
callbackStep(node1, node2) or
109-
collectionsEdge(node1, node2) or
110-
getEdge(node1, node2) or
111-
generalAssignEdge(node1, node2) or
112-
exists(Parameter p | p = node1.asParameter() and
103+
callbackStep(node1, node2)
104+
or
105+
collectionsEdge(node1, node2)
106+
or
107+
getEdge(node1, node2)
108+
or
109+
generalAssignEdge(node1, node2)
110+
or
111+
exists(Parameter p |
112+
p = node1.asParameter() and
113113
node2.asExpr() = p.getAnAccess()
114-
) or
114+
)
115+
or
115116
copyConstructorEdge(node1, node2)
116117
or
117118
pointerTransferEdge(node1, node2)
@@ -134,4 +135,4 @@ class CallbackConfig extends DataFlow::Configuration {
134135
or
135136
forRangeEdge(node1, node2)
136137
}
137-
}
138+
}

0 commit comments

Comments
 (0)