You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/customizing-library-models-for-go.rst
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ The first five values identify the function (in this case a method) to be modele
98
98
- The second value ``DB`` is the name of the type that the method is associated with.
99
99
- The third value ``True`` is a flag that indicates whether or not the sink also applies to subtypes. This includes when the subtype embeds the given type, so that the method or field is promoted to be a method or field of the subtype. For interface methods it also includes types which implement the interface type.
100
100
- The fourth value ``Prepare`` is the method name.
101
-
- The fifth value ``""`` is the method input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions or methods may have the same name and they need to be distinguished by the number and types of the arguments.
101
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
102
102
103
103
The sixth value should be left empty and is out of scope for this documentation.
104
104
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the sink.
@@ -139,7 +139,7 @@ The first five values identify the function to be modeled as a source.
139
139
- The second value ``Request`` is the type name, since the function is a method of the ``Request`` type.
140
140
- The third value ``True`` is a flag that indicates whether or not the sink also applies to subtypes. This includes when the subtype embeds the given type, so that the method or field is promoted to be a method or field of the subtype. For interface methods it also includes types which implement the interface type.
141
141
- The fourth value ``FormValue`` is the function name.
142
-
- The fifth value ``""`` is the function input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions or methods may have the same name and they need to be distinguished by the number and types of the arguments.
142
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
143
143
144
144
The sixth value should be left empty and is out of scope for this documentation.
145
145
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the source.
@@ -156,11 +156,9 @@ This pattern covers many of the cases where we need to summarize flow through a
156
156
157
157
.. code-block:: go
158
158
159
-
import "slices"
160
-
161
159
func ValueFlow {
162
160
a := []int{1, 2, 3}
163
-
max := slices.Max(a) // There is taint flow from `a` to `max`.
161
+
max := slices.Max(a) // There is value flow from the elements of `a` to `max`.
164
162
...
165
163
}
166
164
@@ -173,25 +171,23 @@ We need to add a tuple to the ``summaryModel``\(package, type, subtypes, name, s
Since we are adding flow through a method, we need to add tuples to the ``summaryModel`` extensible predicate.
179
-
Each tuple defines flow from one argument to the return value.
180
177
The first row defines flow from the first argument (``a`` in the example) to the return value (``max`` in the example).
181
178
182
179
The first five values identify the function to be modeled as a summary.
183
-
These are the same for both of the rows above as we are adding two summaries for the same method.
184
180
185
181
- The first value ``slices`` is the package name.
186
182
- The second value ``""`` is left blank, since the function is not a method of a type.
187
183
- The third value ``False`` is a flag that indicates whether or not the sink also applies to subtypes. This has no effect for non-method functions.
188
184
- The fourth value ``Max`` is the function name.
189
-
- The fifth value ``""`` is left blank, since specifying the signature is optional and Go does not allow multiple signature overloads for the same function.
185
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
190
186
191
187
The sixth value should be left empty and is out of scope for this documentation.
192
188
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
193
189
194
-
- The seventh value is the access path to the input (where data flows from). ``Argument[0]`` is the access path to the first argument.
190
+
- The seventh value is the access path to the input (where data flows from). ``Argument[0].ArrayElement`` is the access path to the array elements of the first argument (the elements of the slice in the example).
195
191
- The eighth value ``ReturnValue`` is the access path to the output (where data flows to), in this case ``ReturnValue``, which means that the input flows to the return value.
196
192
- The ninth value ``value`` is the kind of the flow. ``value`` flow indicates an entire value is moved, ``taint`` means that taint is propagated through the call.
197
193
- The tenth value ``manual`` is the provenance of the summary, which is used to identify the origin of the summary.
@@ -204,8 +200,6 @@ This pattern covers many of the cases where we need to summarize flow through a
204
200
205
201
.. code-block:: go
206
202
207
-
import "slices"
208
-
209
203
func ValueFlow {
210
204
a := []int{1, 2, 3}
211
205
b := []int{4, 5, 6}
@@ -222,26 +216,24 @@ We need to add a tuple to the ``summaryModel``\(package, type, subtypes, name, s
Since we are adding flow through a method, we need to add tuples to the ``summaryModel`` extensible predicate.
228
-
Each tuple defines flow from one argument to the return value.
229
-
The first row defines flow from the arguments (``a`` and ``b`` in the example) to the return value (``c`` in the example) and the second row defines flow from the second argument (``sep`` in the example) to the return value (``t`` in the example).
222
+
The first row defines flow from the arguments (``a`` and ``b`` in the example) to the return value (``c`` in the example).
230
223
231
224
The first five values identify the function to be modeled as a summary.
232
-
These are the same for both of the rows above as we are adding two summaries for the same method.
233
225
234
226
- The first value ``slices`` is the package name.
235
227
- The second value ``""`` is left blank, since the function is not a method of a type.
236
228
- The third value ``False`` is a flag that indicates whether or not the sink also applies to subtypes. This has no effect for non-method functions.
237
229
- The fourth value ``Max`` is the function name.
238
-
- The fifth value ``""`` is left blank, since specifying the signature is optional and Go does not allow multiple signature overloads for the same function.
230
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
239
231
240
232
The sixth value should be left empty and is out of scope for this documentation.
241
233
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
242
234
243
-
- The seventh value is the access path to the input (where data flows from). ``Argument[0]`` is the access path to the first argument.
244
-
- The eighth value ``ReturnValue`` is the access path to the output (where data flows to), in this case ``ReturnValue``, which means that the input flows to the return value.
235
+
- The seventh value is the access path to the input (where data flows from). ``Argument[0].ArrayElement.ArrayElement`` is the access path to the array elements of the array elements of the first argument. Note that a variadic parameter of type `...T` is treated as if it has type `[]T` and arguments corresponding to the variadic parameter are accessed as elements of this slice.
236
+
- The eighth value ``ReturnValue.ArrayElement`` is the access path to the output (where data flows to), in this case ``ReturnValue.ArrayElement``, which means that the input flows to the array elements of the return value.
245
237
- The ninth value ``value`` is the kind of the flow. ``value`` flow indicates an entire value is moved, ``taint`` means that taint is propagated through the call.
246
238
- The tenth value ``manual`` is the provenance of the summary, which is used to identify the origin of the summary.
247
239
@@ -282,7 +274,7 @@ These are the same for both of the rows above as we are adding two summaries for
282
274
- The second value ``""`` is left blank, since the function is not a method of a type.
283
275
- The third value ``False`` is a flag that indicates whether or not the sink also applies to subtypes. This has no effect for non-method functions.
284
276
- The fourth value ``Join`` is the function name.
285
-
- The fifth value ``""`` is left blank, since specifying the signature is optional and Go does not allow multiple signature overloads for the same function.
277
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
286
278
287
279
The sixth value should be left empty and is out of scope for this documentation.
288
280
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
@@ -337,7 +329,7 @@ The first five values identify the function (in this case a method) to be modele
337
329
- The second value ``URL`` is the receiver type.
338
330
- The third value ``True`` is a flag that indicates whether or not the sink also applies to subtypes. This includes when the subtype embeds the given type, so that the method or field is promoted to be a method or field of the subtype. For interface methods it also includes types which implement the interface type.
339
331
- The fourth value ``Hostname`` is the method name.
340
-
- The fifth value ``""`` is left blank, since specifying the signature is optional and Go does not allow multiple signature overloads for the same function.
332
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
341
333
342
334
The sixth value should be left empty and is out of scope for this documentation.
343
335
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
@@ -376,7 +368,7 @@ The first five values identify the field to be modeled as a source.
376
368
- The second value ``Request`` is the name of the type that the field is associated with.
377
369
- The third value ``True`` is a flag that indicates whether or not the sink also applies to subtypes. For fields this means when the field is accessed as a promoted field in another type.
378
370
- The fourth value ``Body`` is the field name.
379
-
- The fifth value ``""`` is blank since it is a field access and field accesses do not have method signatures in Go.
371
+
- The fifth value ``""`` is the input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions may have the same name and they need to be distinguished by the number and types of the arguments.
380
372
381
373
The sixth value should be left empty and is out of scope for this documentation.
382
374
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the source.
0 commit comments