Skip to content

Commit b041829

Browse files
committed
Shared: steps in synthetic path chains should just mention the same synthetic fields.
1 parent aae8660 commit b041829

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

shared/dataflow/codeql/dataflow/internal/ContentDataFlowImpl.qll

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ module MakeImplContentDataFlow<LocationSig Location, InputSig<Location> Lang> {
272272
)
273273
}
274274

275-
private ContentSet getAtIndex(int i) {
275+
/**
276+
* Gets the content set at index `i` in this access path, if any.
277+
*/
278+
ContentSet getAtIndex(int i) {
276279
i = 0 and
277280
result = this.getHead()
278281
or
@@ -286,23 +289,6 @@ module MakeImplContentDataFlow<LocationSig Location, InputSig<Location> Lang> {
286289
i >= 0 and
287290
result = TAccessPathCons(this.getAtIndex(i), this.reverse0(i - 1))
288291
}
289-
290-
/**
291-
* Gets the length of this access path.
292-
*/
293-
private int length() {
294-
result = 0 and this = TAccessPathNil()
295-
or
296-
result = 1 + this.getTail().length()
297-
}
298-
299-
/**
300-
* Gets the reversed access path, if any.
301-
*
302-
* Note that not all access paths have a reverse as these are not
303-
* included by default in the IPA type.
304-
*/
305-
AccessPath reverse() { result = this.reverse0(this.length() - 1) }
306292
}
307293

308294
/**

shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,27 @@ module MakeModelGenerator<
677677
)
678678
}
679679

680+
private string getReversedHash(PropagateContentFlow::AccessPath ap) {
681+
result = concat(int i | | getSyntheticName(ap.getAtIndex(i)), "" order by i desc)
682+
}
683+
684+
private string getHash(PropagateContentFlow::AccessPath ap) {
685+
result = concat(int i | | getSyntheticName(ap.getAtIndex(i)), "" order by i)
686+
}
687+
688+
/**
689+
* Gets all access paths that contains the synthetic fields
690+
* from `ap` in reverse order (if `ap` contains at least one synthetic field).
691+
* These are the possible candidates for synthetic path continuations.
692+
*/
693+
private PropagateContentFlow::AccessPath getSyntheticPathCandidate(
694+
PropagateContentFlow::AccessPath ap
695+
) {
696+
hasSyntheticContent(ap) and
697+
hasSyntheticContent(result) and
698+
getHash(ap) = getReversedHash(result)
699+
}
700+
680701
/**
681702
* A module containing predicates for validating access paths containing content sets
682703
* that translates into synthetic fields, when used for generated summary models.
@@ -740,7 +761,7 @@ module MakeModelGenerator<
740761
exists(PropagateContentFlow::AccessPath mid, Type midType |
741762
hasSyntheticContent(mid) and
742763
step(t, read, midType, mid) and
743-
reachesSynthExit(midType, mid.reverse())
764+
reachesSynthExit(midType, getSyntheticPathCandidate(mid))
744765
)
745766
}
746767

@@ -756,7 +777,7 @@ module MakeModelGenerator<
756777
exists(PropagateContentFlow::AccessPath mid, Type midType |
757778
hasSyntheticContent(mid) and
758779
step(midType, mid, t, store) and
759-
synthEntryReaches(midType, mid.reverse())
780+
synthEntryReaches(midType, getSyntheticPathCandidate(mid))
760781
)
761782
}
762783

@@ -785,14 +806,15 @@ module MakeModelGenerator<
785806
Type t1, PropagateContentFlow::AccessPath read, Type t2,
786807
PropagateContentFlow::AccessPath store
787808
) {
788-
synthPathEntry(t1, read, t2, store) and reachesSynthExit(t2, store.reverse())
809+
synthPathEntry(t1, read, t2, store) and
810+
reachesSynthExit(t2, getSyntheticPathCandidate(store))
789811
or
790-
exists(PropagateContentFlow::AccessPath store0 | store0.reverse() = read |
812+
exists(PropagateContentFlow::AccessPath store0 | getSyntheticPathCandidate(store0) = read |
791813
synthEntryReaches(t1, store0) and synthPathExit(t1, read, t2, store)
792814
or
793815
synthEntryReaches(t1, store0) and
794816
step(t1, read, t2, store) and
795-
reachesSynthExit(t2, store.reverse())
817+
reachesSynthExit(t2, getSyntheticPathCandidate(store))
796818
)
797819
}
798820
}

0 commit comments

Comments
 (0)