-
Notifications
You must be signed in to change notification settings - Fork 77
Michaelrfairhurst/package undefined behavior mismatched list delete #1084
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
Closed
MichaelRFairhurst
wants to merge
54
commits into
michaelrfairhurst/package-undefined-behavior
from
michaelrfairhurst/package-undefined-behavior-mismatched-list-delete
Closed
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
32f3d54
First implementation of Rule 22-3-1
MichaelRFairhurst 117afb6
update pack locks
MichaelRFairhurst 4c3f971
Bump actions/checkout from 5 to 6
dependabot[bot] c29ca80
Add lifetime rule RULE-11-6-2
knewbury01 5830686
Merge branch 'main' into dependabot/github_actions/actions/checkout-6
MichaelRFairhurst 0d02cef
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/pre…
MichaelRFairhurst b72d975
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/pre…
MichaelRFairhurst 4eeadb0
Merge branch 'main' into michaelrfairhurst/preconditions-rule-22-3-1-…
MichaelRFairhurst 3d71876
Merge branch 'main' into michaelrfairhurst/preconditions-rule-22-3-1-…
MichaelRFairhurst cbec99e
Merge branch 'main' into michaelrfairhurst/preconditions-rule-22-3-1-…
MichaelRFairhurst 6fb7d61
Bump version to 2.56.0-dev
knewbury01 6956667
Merge branch 'main' into knewbury01/Lifetime
knewbury01 c38d0ee
Merge pull request #1073 from github/release-automation/bump-version-…
knewbury01 86123fe
Update cpp/common/src/codingstandards/cpp/standardlibrary/Assert.qll
mbaluda 9651122
Add improvements to readofuninitializedmemory and testcase
knewbury01 d0f2ede
Remove unnecessary import in readofuninitializedmemory
knewbury01 1c610ee
Add shared query for RULE-6-8-3
knewbury01 a903b40
Merge branch 'main' into knewbury01/Lifetime
knewbury01 1704bb8
Format query
knewbury01 dd5ebd3
Merge branch 'knewbury01/Lifetime' of https://github.com/knewbury01/c…
knewbury01 ac21481
Add another missing query format
knewbury01 b2e8f3a
Revert shared rule to class not module since it shares with old style
knewbury01 1649c21
Improve tests to be more clear on whether certain cases are supported…
knewbury01 9e62570
Import EXP51-CPP into rule 4-1-3 as it is UB
MichaelRFairhurst 5680bbd
Bump actions/create-github-app-token from 2 to 3
dependabot[bot] f5501da
Comment fix on aborts+asserts
MichaelRFairhurst 8071ddb
Merge pull request #986 from github/michaelrfairhurst/preconditions-r…
MichaelRFairhurst af8a42b
Merge pull request #985 from github/dependabot/github_actions/actions…
MichaelRFairhurst 25403fc
Merge pull request #1085 from github/dependabot/github_actions/action…
MichaelRFairhurst db1a631
Address review comments
knewbury01 3baadfb
Fix testcase formatting
knewbury01 242422b
Address review comments
knewbury01 10f562a
Merge branch 'main' into knewbury01/Lifetime
knewbury01 1487ba0
Merge pull request #1024 from knewbury01/knewbury01/Lifetime
MichaelRFairhurst f739b65
Add RULE-13-3-3
knewbury01 f999e10
Fix testcase labelling RULE-13-3-3
knewbury01 c6997fd
Address review comment
knewbury01 a4ca148
Apply a few other review comments
knewbury01 1371769
Merge branch 'main' into knewbury01/misracpp2023-declarations1
knewbury01 ad580d3
Merge pull request #1089 from knewbury01/knewbury01/misracpp2023-decl…
MichaelRFairhurst 664a54a
Add query validation guidelines to copilot review instructions
mbaluda 83cf49c
Revise QLDoc style guide and add examples
mbaluda 26402a3
Update .github/copilot-instructions.md
mbaluda b65b58f
Update .github/copilot-instructions.md
mbaluda 5364072
Update .github/copilot-instructions.md
mbaluda 0c29859
Update .github/copilot-instructions.md
mbaluda fb0af07
Update CodeQL guidelines and QLDoc requirements
mbaluda df3074e
Merge pull request #1092 from github/mbaluda-patch-1
mbaluda c148d75
Merge branch 'main' into michaelrfairhurst/package-undefined-behavior…
mbaluda 8e8feef
Update .github/workflows/validate-query-formatting.yml
mbaluda 9d539a3
Address copilot review
mbaluda 8ba9aff
Fix expected file
mbaluda e57263b
Merge branch 'michaelrfairhurst/package-undefined-behavior' into mich…
MichaelRFairhurst 614a802
Merge remote-tracking branch 'origin/michaelrfairhurst/package-undefi…
MichaelRFairhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
change_notes/2026-03-13-share-array-delete-type-mismatch-query.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - `EXP51-CPP` - `DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.ql`: | ||
| - Refactored query logic into a shared library (`DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.qll`) to enable reuse by MISRA C++ `RULE-4-1-3`. The query logic is unchanged and no visible changes to results or performance are expected. | ||
| - The query now uses a `query predicate problems` instead of a `from/where/select`. In path-problem BQRS output, the results section header changes from `#select` to `problems`. Alert results and their content are otherwise identical. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.expected
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.qlref
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.testref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cpp/common/test/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...teroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Provides a configurable module DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared | ||
| * with a `problems` predicate for the following issue: | ||
| * Deleting an array through a pointer of an incorrect type leads to undefined behavior. | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.Customizations | ||
| import codingstandards.cpp.Exclusions | ||
| import semmle.code.cpp.dataflow.DataFlow | ||
|
|
||
| signature module DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeSharedConfigSig { | ||
| Query getQuery(); | ||
| } | ||
|
|
||
| module DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared< | ||
| DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeSharedConfigSig Config> | ||
| { | ||
| private module AllocationToDeleteConfig implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node source) { source.asExpr() instanceof NewArrayExpr } | ||
|
|
||
| predicate isSink(DataFlow::Node sink) { | ||
| exists(DeleteArrayExpr dae | dae.getExpr() = sink.asExpr()) | ||
| } | ||
| } | ||
|
|
||
| module AllocationToDeleteFlow = DataFlow::Global<AllocationToDeleteConfig>; | ||
|
|
||
| module PathGraph = AllocationToDeleteFlow::PathGraph; | ||
|
|
||
| query predicate problems( | ||
| Expr deleteExpr, AllocationToDeleteFlow::PathNode source, AllocationToDeleteFlow::PathNode sink, | ||
| string message | ||
| ) { | ||
| exists(NewArrayExpr newArray, DeleteArrayExpr deleteArray | | ||
| not isExcluded(deleteArray.getExpr(), Config::getQuery()) and | ||
| AllocationToDeleteFlow::flowPath(source, sink) and | ||
| newArray = source.getNode().asExpr() and | ||
| deleteArray.getExpr() = sink.getNode().asExpr() and | ||
| not newArray.getType().getUnspecifiedType() = | ||
| deleteArray.getExpr().getType().getUnspecifiedType() and | ||
| deleteExpr = sink.getNode().asExpr() and | ||
| message = | ||
| "Array of type " + newArray.getType() + " is deleted through a pointer of type " + | ||
| deleteArray.getExpr().getType() + "." | ||
| ) | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
...theincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| problems | ||
| | test.cpp:9:12:9:13 | l1 | test.cpp:6:19:6:37 | new[] | test.cpp:9:12:9:13 | l1 | Array of type DerivedClass * is deleted through a pointer of type BaseClass *. | | ||
| edges | ||
| | test.cpp:6:19:6:37 | new[] | test.cpp:9:12:9:13 | l1 | provenance | | | ||
| | test.cpp:7:22:7:40 | new[] | test.cpp:10:12:10:13 | l2 | provenance | | | ||
| nodes | ||
| | test.cpp:6:19:6:37 | new[] | semmle.label | new[] | | ||
| | test.cpp:7:22:7:40 | new[] | semmle.label | new[] | | ||
| | test.cpp:9:12:9:13 | l1 | semmle.label | l1 | | ||
| | test.cpp:10:12:10:13 | l2 | semmle.label | l2 | | ||
| subpaths |
11 changes: 11 additions & 0 deletions
11
...nteroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // GENERATED FILE - DO NOT MODIFY | ||
| import codingstandards.cpp.rules.donotdeleteanarraythroughapointeroftheincorrecttypeshared.DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared | ||
|
|
||
| module TestFileConfig implements DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeSharedConfigSig { | ||
| Query getQuery() { result instanceof TestQuery } | ||
| } | ||
|
|
||
| module Shared = DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared<TestFileConfig>; | ||
|
|
||
| import Shared::PathGraph | ||
| import Shared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
cpp/misra/src/rules/RULE-4-1-3/ArrayDeletedThroughPointerOfIncorrectType.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * @id cpp/misra/array-deleted-through-pointer-of-incorrect-type | ||
| * @name RULE-4-1-3: Array deleted through pointer of incorrect type leads to undefined behavior | ||
| * @description Deleting an array through a pointer of an incorrect type leads to undefined | ||
| * behavior. | ||
| * @kind path-problem | ||
| * @precision high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-4-1-3 | ||
| * correctness | ||
| * scope/system | ||
| * external/misra/enforcement/undecidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
| import codingstandards.cpp.rules.donotdeleteanarraythroughapointeroftheincorrecttypeshared.DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared | ||
|
|
||
| module ArrayDeletedThroughPointerOfIncorrectTypeConfig implements | ||
| DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeSharedConfigSig | ||
| { | ||
| Query getQuery() { result = UndefinedPackage::arrayDeletedThroughPointerOfIncorrectTypeQuery() } | ||
| } | ||
|
|
||
| module Shared = | ||
| DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared<ArrayDeletedThroughPointerOfIncorrectTypeConfig>; | ||
|
|
||
| import Shared::PathGraph | ||
| import Shared |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-4-1-3/ArrayDeletedThroughPointerOfIncorrectType.testref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cpp/common/test/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.