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 4, 2024
1 parent 662a824 commit 8b8b721
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions shared/dataflow/codeql/dataflow/test/ProvenancePathGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,36 @@ private module TranslateModels<
)
}

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

// collapse models with the same textual representation, in order to not rely
// on the order of `ExtensionId`s
private module ExtensionIdSets =
QlBuiltins::InternSets<string, QlBuiltins::ExtensionId, getModelId/1>;

private predicate rankedMadIds(ExtensionIdSets::Set extIdSet, int r) {
extIdSet =
rank[r](ExtensionIdSets::Set extIdSet0, string model |
extIdSet0 = ExtensionIdSets::getSet(model)
|
extIdSet0 order by model
)
}

private predicate translateModel(string id, int r) {
exists(QlBuiltins::ExtensionId madId, ExtensionIdSets::Set extIdSet |
id = madId.toString() and
extIdSet.contains(madId) and
rankedMadIds(extIdSet, r)
)
}

/** 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(string madId | translateModel(madId, r) and getModelId(model).toString() = madId)
}

private predicate translateModelsPart(string model1, string model2, int i) {
Expand All @@ -46,7 +67,7 @@ private module TranslateModels<
translateModelsPart(model1, part, i - 1) and
madId = s.regexpCapture("([0-9]*)(.*)", 1) and
rest = s.regexpCapture("([0-9]*)(.*)", 2) and
rankedMadIds(madId, r) and
translateModel(madId, r) and
model2 = part + "MaD:" + r + rest
)
)
Expand Down Expand Up @@ -102,17 +123,6 @@ module TestPostProcessing {

private module Models = TranslateModels<interpretModelForTest/2, provenance/1>;

private newtype TModelRow = TMkModelRow(int r, string model) { Models::models(r, model) }

private predicate rankedModels(int i, int r, string model) {
TMkModelRow(r, model) =
rank[i](TModelRow row, int r0, string model0 |
row = TMkModelRow(r0, model0)
|
row order by r0, model0
)
}

query predicate results(string relation, int row, int column, string data) {
queryResults(relation, row, column, data) and
(relation != "edges" or column != provenanceColumn())
Expand All @@ -124,11 +134,11 @@ module TestPostProcessing {
Models::translateModels(model, data)
)
or
exists(int r, string model |
exists(string model |
relation = "models" and
rankedModels(row, r, model)
Models::models(row, model)
|
column = 0 and data = r.toString()
column = 0 and data = row.toString()
or
column = 1 and data = model
)
Expand Down

0 comments on commit 8b8b721

Please sign in to comment.