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
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -195,6 +195,56 @@ The remaining values are used to define the ``access path``, the ``kind``, and t
195
195
- 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
196
- 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
197
- The tenth value ``manual`` is the provenance of the summary, which is used to identify the origin of the summary.
198
+
199
+
Example: Add flow through the ``Concat`` function
200
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
201
+
202
+
This example shows how the Go query pack models flow through a function for a simple case.
203
+
This pattern covers many of the cases where we need to summarize flow through a function that is stored in a library or framework outside the repository.
204
+
205
+
.. code-block:: go
206
+
207
+
import "slices"
208
+
209
+
func ValueFlow {
210
+
a := []int{1, 2, 3}
211
+
b := []int{4, 5, 6}
212
+
c := slices.Concat(a, b) // There is taint flow from `a` and `b` to `c`.
213
+
...
214
+
}
215
+
216
+
We need to add a tuple to the ``summaryModel``\(package, type, subtypes, name, signature, ext, input, output, kind, provenance) extensible predicate by updating a data extension file:
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).
230
+
231
+
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
+
234
+
- The first value ``slices`` is the package name.
235
+
- The second value ``""`` is left blank, since the function is not a method of a type.
236
+
- 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
+
- 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.
239
+
240
+
The sixth value should be left empty and is out of scope for this documentation.
241
+
The remaining values are used to define the ``access path``, the ``kind``, and the ``provenance`` (origin) of the summary.
242
+
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.
245
+
- 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
+
- The tenth value ``manual`` is the provenance of the summary, which is used to identify the origin of the summary.
247
+
198
248
Example: Add flow through the ``Join`` function
199
249
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200
250
This example shows how the Go query pack models flow through a method for a simple case.
0 commit comments