Skip to content

Commit 86c7a49

Browse files
egregius313owen-mc
andauthored
Apply suggestions from code review
Co-authored-by: Owen Mansel-Chan <[email protected]>
1 parent 8c6e08c commit 86c7a49

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

docs/codeql/codeql-language-guides/customizing-library-models-for-go.rst

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The first five values identify the function (in this case a method) to be modele
9898
- The second value ``DB`` is the name of the type that the method is associated with.
9999
- 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.
100100
- 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.
102102

103103
The sixth value should be left empty and is out of scope for this documentation.
104104
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.
139139
- The second value ``Request`` is the type name, since the function is a method of the ``Request`` type.
140140
- 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.
141141
- 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.
143143

144144
The sixth value should be left empty and is out of scope for this documentation.
145145
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
156156

157157
.. code-block:: go
158158
159-
import "slices"
160-
161159
func ValueFlow {
162160
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`.
164162
...
165163
}
166164
@@ -173,25 +171,23 @@ We need to add a tuple to the ``summaryModel``\(package, type, subtypes, name, s
173171
pack: codeql/go-all
174172
extensible: summaryModel
175173
data:
176-
- ["slices", "", True, "Max", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"]
174+
- ["slices", "", False, "Max", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"]
177175
178176
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.
180177
The first row defines flow from the first argument (``a`` in the example) to the return value (``max`` in the example).
181178

182179
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.
184180

185181
- The first value ``slices`` is the package name.
186182
- The second value ``""`` is left blank, since the function is not a method of a type.
187183
- 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.
188184
- 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.
190186

191187
The sixth value should be left empty and is out of scope for this documentation.
192188
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
193189

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).
195191
- 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.
196192
- 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.
197193
- 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
204200

205201
.. code-block:: go
206202
207-
import "slices"
208-
209203
func ValueFlow {
210204
a := []int{1, 2, 3}
211205
b := []int{4, 5, 6}
@@ -222,26 +216,24 @@ We need to add a tuple to the ``summaryModel``\(package, type, subtypes, name, s
222216
pack: codeql/go-all
223217
extensible: summaryModel
224218
data:
225-
- ["slices", "", True, "Concat", "", "", "Argument[0].ArrayElement.ArrayElement", "ReturnValue.ArrayElement", "value", "manual"]
219+
- ["slices", "", False, "Concat", "", "", "Argument[0].ArrayElement.ArrayElement", "ReturnValue.ArrayElement", "value", "manual"]
226220
227221
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).
230223

231224
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.
233225

234226
- The first value ``slices`` is the package name.
235227
- The second value ``""`` is left blank, since the function is not a method of a type.
236228
- 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.
237229
- 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.
239231

240232
The sixth value should be left empty and is out of scope for this documentation.
241233
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
242234

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.
245237
- 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.
246238
- The tenth value ``manual`` is the provenance of the summary, which is used to identify the origin of the summary.
247239

@@ -282,7 +274,7 @@ These are the same for both of the rows above as we are adding two summaries for
282274
- The second value ``""`` is left blank, since the function is not a method of a type.
283275
- 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.
284276
- 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.
286278

287279
The sixth value should be left empty and is out of scope for this documentation.
288280
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
337329
- The second value ``URL`` is the receiver type.
338330
- 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.
339331
- 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.
341333

342334
The sixth value should be left empty and is out of scope for this documentation.
343335
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.
376368
- The second value ``Request`` is the name of the type that the field is associated with.
377369
- 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.
378370
- 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.
380372

381373
The sixth value should be left empty and is out of scope for this documentation.
382374
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the source.

0 commit comments

Comments
 (0)