-
Notifications
You must be signed in to change notification settings - Fork 372
[swiftsrc2cpg] Extension handling rework #5707
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
base: master
Are you sure you want to change the base?
Conversation
- fix fullnames with references to extension from libraries - account for modifiers in compiler json output
76276be to
f2ea73d
Compare
| val List(fooCallReceiver) = fooCall.receiver.isIdentifier.l | ||
| fooCallReceiver.name shouldBe "self" | ||
| fooCallReceiver.typeFullName shouldBe "SwiftTest.Foo" |
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.
self is should not be given as receiver. It should only be an argument. Receiver relation in the CPG is only valid for dynamically dispatched calls.
| val List(barCallReceiverCall) = barCall.receiver.isIdentifier.l | ||
| barCallReceiverCall.name shouldBe "self" | ||
| barCallReceiverCall.typeFullName shouldBe "SwiftTest.Foo" |
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.
Same as above.
| fooTypeDecl.fullName shouldBe "ModuleA.Foo" | ||
|
|
||
| val List(foo) = cpg.method.nameExact("foo").l | ||
| foo.fullName shouldBe "ModuleA.Foo<extension>.foo:()->()" |
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.
Why does foo not have the full name ModuleA.ModuleA.Foo<extension>.foo:()->()?
Seems like you use a different naming pattern for extension in the same module as the extended type. I think a uniform naming schema is better or am I missing some reason other than the shorter full name?
| * "Test0.swift:<global>.Foo<extension>.someOtherFunc:()->ANY" ) | ||
| */ | ||
|
|
||
| typeDeclFoo.inheritsFromTypeFullName.sorted.l shouldBe List("AnotherProtocol", "Bar", "SomeProtocol") |
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.
These are not full names. We need to talk about your type full name concept. As those contain file names they do not seem appropriate for linking.
| * @param extensionFullNameMapping | ||
| * mapping from compiler generated methodFullName -> CPG extension methodFullName (for uniqueness) | ||
| */ | ||
| class ExtensionCallPass(cpg: Cpg, extensionFullNameMapping: Map[String, String]) |
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 think the approach of fixing up the call sites later has reached its end because as mentioned about the receiver edges are wrong for static calls. Of course we could now remove them here but a pre-pass which collects the necessary information to directly generate the correct calls seems more appropriate.
<extension>tag in their fullNames for each function in the extension and binds them appropriately. No TypeDecl is generated for the extension itself.inheritsFromlogic was updated to work for both regular type declarations and extensions, and inheritance relationships for extensions are now registered globally for later processing in a separate pass.selfand initializer return types are correct.Needs a fix at: https://github.com/ShiftLeftSecurity/codescience/blob/c8d155ffd34ccb6d1f8296a5722a9edeaa8a5c30/securityprofile/src/main/scala/io/shiftleft/securityprofile/passes/finalcustom/swiftsrc/generic/NSURLConnCertCheckPass.scala#L36
Will do that in a PR at CS.