Skip to content

Commit

Permalink
Data flow: Order provenance output by textual representation
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Nov 1, 2024
1 parent 2b37c6c commit b2d03c7
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions shared/dataflow/codeql/dataflow/test/ProvenancePathGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,42 @@ private module TranslateModels<
)
}

private predicate rankedMadIds(string madId, int r) {
madId = rank[r](string madId0 | madIds(madId0) | madId0 order by madId0.toInt())
private predicate interpretRelevantModelForTest(int id, string model) {
exists(QlBuiltins::ExtensionId madId |
madIds(madId.toString()) and
interpretModelForTest(madId, model) and
id = madId.toString().toInt()
)
}

// in case multiple models share the same textual representation, collapse them
// in the output
private predicate interpretRelevantModelForTestMinId(int id, string model) {
id = min(int id0 | interpretRelevantModelForTest(id0, model))
}

private predicate rankedMadIds(int madId, int r) {
madId =
rank[r](int madId0, string model |
interpretRelevantModelForTestMinId(madId0, model)
|
madId0 order by model
)
}

/** Lists the renumbered and pretty-printed models used in the edges relation. */
predicate models(int r, string model) {
exists(QlBuiltins::ExtensionId madId |
rankedMadIds(madId.toString(), r) and interpretModelForTest(madId, model)
)
exists(int madId | rankedMadIds(madId, r) and interpretRelevantModelForTestMinId(madId, model))
}

private predicate translateModelsPart(string model1, string model2, int i) {
provenance(model1) and
exists(string s | model1.splitAt("MaD:", i) = s |
model2 = s and i = 0
or
exists(string part, string madId, string rest, int r |
exists(string part, int madId, string rest, int r |
translateModelsPart(model1, part, i - 1) and
madId = s.regexpCapture("([0-9]*)(.*)", 1) and
madId = s.regexpCapture("([0-9]*)(.*)", 1).toInt() and
rest = s.regexpCapture("([0-9]*)(.*)", 2) and
rankedMadIds(madId, r) and
model2 = part + "MaD:" + r + rest
Expand Down

0 comments on commit b2d03c7

Please sign in to comment.