-
Notifications
You must be signed in to change notification settings - Fork 59
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
Implement InvalidMemory3, Rule 18-8 amendment. #750
base: main
Are you sure you want to change the base?
Implement InvalidMemory3, Rule 18-8 amendment. #750
Conversation
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.
Thanks! Some suggestions and comments to follow up on individual files.
|
||
// A typedef is not a VLA. However, `VlaDeclStmt`s match the typedef. | ||
typedef int vlaTypedef[n]; // COMPLIANT[FALSE_POSITIVE] | ||
vlaTypedef t1; // NON_COMPLIANT[FALSE_NEGATIVE] |
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 we should remove the false positive and false negative markers here, and accept the existing results as correct.
I justify this in two ways:
- It's more developer friendly to highlight the typedef that introduces the VLA, rather than the actual declaration. It's where they would likely need to fix the problem, and it reduces the number of results that need to be managed vs. every use of the typedef.
- I think that's consistent with how MISRA intended to report the results. This forum post https://forum.misra.org.uk/archive/index.php?thread-1384.html, while not being 100% clear, I think is indicative that typedefs themselves should be considered a use of variable-length arrays.
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'm happy to do it that way, and I think the first point is a good reason why we would want to do it this way. That said, in my conversations with Robert, our conclusion was that 18-8 is intended to reject allocating VLAs. It's the allocation of a VLA that makes them so dangerous to use. In my head, a VLA is an object in memory, while a VLA type is the static type of that object, and the rule now states that it's VLAs which are banned, not VLA types.
Of course, an unused VLA typedef should be deleted. And most uses of a VLA typedef would be invalid. But in theory, not all. A VLA typedef could be used in a sizeof()
, or it could be used in a context where it is adjusted to a pointer.
I don't think these cases are likely to come up, I did want to document them correctly in the tests.
Perhaps I should add this explanation in a comment?
s.getADeclaration() = entry.getDeclaration() and | ||
before = s.getLocation() and | ||
after = before and | ||
before.subsumes(inner) |
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 we should consider what happens if the declaration is in a macro. Specifically, what happens if a macro has multiple array declarations, only one of which is a VM. I suspect we'll end up flagging all of them, as they will all have the same location.
Note: that is not a problem for the parameter case, because we require a strict before/after location.
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.
We can exclude that case. In general, it'd be easy to exclude all cases where the declaration entry isGeneratedByMacro.
However, it's worth noting that the false positives are incomplete array types. Variables can't be declared with incomplete array types. So the cases where this would flag multiple things because they all match would be a pretty unusual case where, for instance, multiple declared variables have function types with incomplete array types as parameters.
Description
Implements package InvalidMemory3, which detects pointer-to-array conversions and modification of array values with temporary lifetimes, (
RULE-18-9
) and bans pointers to variably modified types (RULE-18-10
).RULE-18-10
is marked as "split" fromRULE-18-8
in the amendments file, so updateRULE-18-8
to only detect allocating VLA declarations. In the process, remove potential false positives around incomplete array parameter types, eg,f(int arr[])
. To protect against the same false positives from occurring inRULE-18-10
, use locations that correspond withVlaDimensionStmt
instances.If it is better to split this PR up, I'm happy to do so!
Change request type
.ql
,.qll
,.qls
or unit tests)Rules with added or modified queries
RULE-18-9
RULE-18-10
RULE-18-8
Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.