Skip to content

Commit ed36f19

Browse files
committed
Python: sync TypeTracker.qll
1 parent ae60b0a commit ed36f19

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ private module Cached {
1212
LevelStep() or
1313
CallStep() or
1414
ReturnStep() or
15-
StoreStep(TypeTrackerContent content) or
16-
LoadStep(TypeTrackerContent content) or
15+
StoreStep(TypeTrackerContent content) { basicStoreStep(_, _, content) } or
16+
LoadStep(TypeTrackerContent content) { basicLoadStep(_, _, content) } or
1717
JumpStep()
1818

1919
pragma[nomagic]
@@ -218,7 +218,18 @@ module StepSummary {
218218
}
219219
}
220220

221-
private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content)
221+
private newtype TTypeTracker =
222+
MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content) {
223+
content = noContent()
224+
or
225+
// Restrict `content` to those that might eventually match a load.
226+
// We can't rely on `basicStoreStep` since `startInContent` might be used with
227+
// a content that has no corresponding store.
228+
exists(TypeTrackerContent loadContents |
229+
basicLoadStep(_, _, loadContents) and
230+
compatibleContents(content, loadContents)
231+
)
232+
}
222233

223234
/**
224235
* A summary of the steps needed to track a value to a given dataflow node.
@@ -372,7 +383,15 @@ module TypeTracker {
372383
}
373384

374385
private newtype TTypeBackTracker =
375-
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content)
386+
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content) {
387+
content = noContent()
388+
or
389+
// As in MkTypeTracker, restrict `content` to those that might eventually match a store.
390+
exists(TypeTrackerContent storeContent |
391+
basicStoreStep(_, _, storeContent) and
392+
compatibleContents(storeContent, content)
393+
)
394+
}
376395

377396
/**
378397
* A summary of the steps needed to back-track a use of a value to a given dataflow node.

0 commit comments

Comments
 (0)