Skip to content
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

Added Swift rule for nil assignment to implicilty unwrapped optional #66

Closed
wants to merge 1 commit into from

Conversation

bismuthsalamander
Copy link

Added a Swift rule for assigning nil to an implicitly unwrapped optional (e.g., var num: Int! = 5; num = nil;). Updated the rule table generator to include Swift as another language. If we wanted, we could put Swift in a subdirectory called iOS with Objective-C rules in there as well (when we write some).

@CLAassistant
Copy link

CLAassistant commented Aug 14, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mschwager mschwager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for writing this rule up!

Comment on lines +23 to +30
- pattern-inside:
pattern-either:
- pattern: |
var $VAR: Int! = nil
(...)
- pattern: |
var $VAR: Int!
(...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I'm kinda surprised this runs. AFAIK, pattern-inside must take a string, not a child YAML object. IMO a better way to structure this would be to have the pattern-either as the parent pattern, and have two pattern-insides underneath.

I think taint mode is another great option here. It perfectly matches what you're trying to achieve here. The patterns above would be the sources, the pattern-nots would be sanitizers, and the pattern below would be the sink.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Given CodeQL's inability to richly express variable types, I'm going to chuck this for a CodeQL version at some point in the future. Thanks!

@mschwager mschwager deleted the swift-first-rule branch August 15, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants