-
Notifications
You must be signed in to change notification settings - Fork 2k
Swift: Model withUnsafeBytes and similar closure methods #13827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
63c71f0
feadd71
315cb32
49d1556
664dc01
c48d474
b41d47b
d24db3f
af8d4e5
063ab1c
6ccf47e
c954324
59e2b04
1ac9d2c
0fd4f61
86a73fa
a6f29fa
b4db68a
a54747f
997984c
6ef6be7
317757b
f7776f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
|
|
||
| * Added flow models of collection `.withContiguous[Mutable]StorageIfAvailable`, `.withUnsafe[Mutable]BufferPointer` and `.withUnsafe[Mutable]Bytes` methods. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,7 +225,12 @@ module Content { | |
| override string toString() { result = "Array element" } | ||
| } | ||
|
|
||
| /** An element of a collection. */ | ||
| /** | ||
| * An element of a collection. This is a broad class including: | ||
| * - elements of collections, such as `Set<Element>`. | ||
| * - elements of buffers, such as `UnsafeBufferPointer<Element>`. | ||
| * - the pointee of a pointer, such as `UnsafePointer<Pointee>`. | ||
|
Comment on lines
+230
to
+232
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a small performance win to split up these three things into separate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| */ | ||
| class CollectionContent extends Content, TCollectionContent { | ||
| override string toString() { result = "Collection element" } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Provides models for the `JavaScriptCore` library. | ||
| */ | ||
|
|
||
| import swift | ||
| private import codeql.swift.dataflow.ExternalFlow | ||
|
|
||
| /** | ||
| * A model for `JavaScriptCore` functions and class members that permit taint flow. | ||
| */ | ||
| private class JSStringSummaries extends SummaryModelCsv { | ||
| override predicate row(string row) { | ||
| row = | ||
| [ | ||
| ";;false;JSStringCreateWithUTF8CString(_:);;;Argument[0];ReturnValue;taint", | ||
| ";;false;JSStringCreateWithCharacters(_:_:);;;Argument[0];ReturnValue;taint", | ||
| ";;false;JSStringRetain(_:);;;Argument[0];ReturnValue;taint", | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,19 @@ module UnsafeJsEvalConfig implements DataFlow::ConfigSig { | |
| predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { | ||
| any(UnsafeJsEvalAdditionalFlowStep s).step(nodeFrom, nodeTo) | ||
| } | ||
|
|
||
| predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) { | ||
| // flow out from content a the sink | ||
| ( | ||
| isSink(node) | ||
| or | ||
| isAdditionalFlowStep(node, _) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm.... Why do we need implicit read steps at the additional flow steps, and not just at the sink? I assume this is related to the ad-hoc model you had to provide for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think that was why, and there's an issue for turning that ad-hoc model into a general one and getting rid of the remaining special cases here. |
||
| ) and | ||
| ( | ||
| c.getAReadContent() instanceof DataFlow::Content::ArrayContent or | ||
| c.getAReadContent() instanceof DataFlow::Content::CollectionContent | ||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once again, I really hope we can merge these eventually. We're straining the dataflow library quite a lot with these duplications (i.e., if we have a path that should have an access path like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that a future PR can either collapse
ArrayContentandCollectionContentinto a single IPA branch, or that we can ensure that a given read/store step always reads a singleContent. But obviously, that's not for this PR to handle. So this LGTM for nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 100%.