CodeQL library for C/C++
codeql/cpp-all 4.3.1 (changelog, source)
Search

Module ExternalFlow

INTERNAL use only. This is an experimental API subject to change without notice.

Provides classes and predicates for dealing with flow models specified in CSV format.

The CSV specification has the following columns:

  • Sources: namespace; type; subtypes; name; signature; ext; output; kind
  • Sinks: namespace; type; subtypes; name; signature; ext; input; kind
  • Summaries: namespace; type; subtypes; name; signature; ext; input; output; kind

The interpretation of a row is similar to API-graphs with a left-to-right reading.

  1. The namespace column selects a namespace.

  2. The type column selects a type within that namespace. This column can introduce template names that can be mentioned in the signature column. For example, vector<T,Allocator> introduces the template names T and Allocator.

  3. The subtypes is a boolean that indicates whether to jump to an arbitrary subtype of that type. Set this to false if leaving the type blank (for example, a free function).

  4. The name column optionally selects a specific named member of the type. Like the type column, this column can introduce template names that can be mentioned in the signature column. For example, insert<InputIt> introduces the template name InputIt.

  5. The signature column optionally restricts the named member. If signature is blank then no such filtering is done. The format of the signature is a comma-separated list of types enclosed in parentheses. The types must be stripped of template names. That is, write const vector & instead of const vector<T> &.

  6. The ext column specifies additional API-graph-like edges. Currently there is only one valid value: "".

  7. The input column specifies how data enters the element selected by the first 6 columns, and the output column specifies how data leaves the element selected by the first 6 columns. An input can be either:

    • "": Selects a write to the selected element in case this is a field.
    • “Argument[n]”: Selects an argument in a call to the selected element. The arguments are zero-indexed, and -1 specifies the qualifier object, that is, *this.
      • one or more “*” can be added in front of the argument index to indicate indirection, for example, Argument[*0] indicates the first indirection of the 0th argument.
      • n1..n2 syntax can be used to indicate a range of arguments, inclusive at both ends. One or more "*"s can be added in front of the whole range to indicate that every argument in the range is indirect, for example *0..1 is the first indirection of both arguments 0 and 1.
    • “ReturnValue”: Selects a value being returned by the selected element. One or more “*” can be added as an argument to indicate indirection, for example, “ReturnValue[*]” indicates the first indirection of the return value. The special symbol @ can be used to specify an arbitrary (but fixed) number of indirections. For example, the input column Argument[*@0] indicates one or more indirections of the 0th argument.

    An output can be either:

    • "": Selects a read of a selected field.
    • “Argument[n]”: Selects the post-update value of an argument in a call to the selected element. That is, the value of the argument after the call returns. The arguments are zero-indexed, and -1 specifies the qualifier object, that is, *this.
      • one or more “*” can be added in front of the argument index to indicate indirection, for example, Argument[*0] indicates the first indirection of the 0th argument.
      • n1..n2 syntax can be used to indicate a range of arguments, inclusive at both ends. One or more "*"s can be added in front of the whole range to indicate that every argument in the range is indirect, for example *0..1 is the first indirection of both arguments 0 and 1.
    • “Parameter[n]”: Selects the value of a parameter of the selected element. The syntax is the same as for “Argument”, for example “Parameter[0]”, “Parameter[*0]”, “Parameter[0..2]” etc.
    • “ReturnValue”: Selects a value being returned by the selected element. One or more “*” can be added as an argument to indicate indirection, for example, “ReturnValue[*]” indicates the first indirection of the return value. The special symbol @ can be used to specify an arbitrary (but fixed) number of indirections. For example, the output column ReturnValue[*@0] indicates one or more indirections of the return value. Note: The symbol @ only ever takes a single value across a row. Thus, the (input, output) pair ("Argument[*@0]", "ReturnValue[@]") represents:
    • flow from the first indirection of the 0th argument to the return value, and
    • flow from the second indirection of the 0th argument to the first indirection of the return value, etc.
  8. The kind column is a tag that can be referenced from QL to determine to which classes the interpreted elements should be added. For example, for sources “remote” indicates a default remote flow source, and for summaries “taint” indicates a default additional taint step and “value” indicates a globally applicable value-preserving step.

Import path

import semmle.code.cpp.dataflow.ExternalFlow

Imports

Cached
cpp

Provides classes and predicates for working with C/C++ code.

Predicates

getFullyTemplatedFunction

Gets the fully templated version of f.

getParameterTypeName

Gets the string representation of the i’th parameter of c.

getParameterTypeWithoutTemplateArguments

Gets a type name for the n’th parameter of f without any template arguments.

modelCoverage

Holds if MaD framework coverage of namespace is n api endpoints of the kind (kind, part), and namespaces is the number of subnamespaces of namespace which have MaD framework coverage (including namespace itself).

sinkModel

Holds if row is a sink model.

sinkModel

Holds if a sink model exists for the given parameters.

sinkNode

Holds if node is specified as a sink with the given kind in a MaD flow model.

sourceModel

Holds if row is a source model.

sourceModel

Holds if a source model exists for the given parameters.

sourceNode

Holds if node is specified as a source with the given kind in a MaD flow model.

summaryModel

Holds if row is a summary model.

summaryModel

Holds if a summary model exists for the given parameters.

Classes

SinkModelCsv

A unit class for adding additional sink model rows.

SourceModelCsv

A unit class for adding additional source model rows.

SummaryModelCsv

A unit class for adding additional summary model rows.

Modules

CsvValidation

Provides a query predicate to check the CSV data for validation errors.

ExternalFlowDebug

Internal: Do not use.