Skip to content

Michaelrfairhurst/package undefined behavior mismatched list delete#1084

Open
MichaelRFairhurst wants to merge 7 commits intomainfrom
michaelrfairhurst/package-undefined-behavior-mismatched-list-delete
Open

Michaelrfairhurst/package undefined behavior mismatched list delete#1084
MichaelRFairhurst wants to merge 7 commits intomainfrom
michaelrfairhurst/package-undefined-behavior-mismatched-list-delete

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

please enter the description of your change here

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • RULE-4-1-3
  • Queries have been modified for the following rules:
    • EXP51-CPP

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
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.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

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

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    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.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    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.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new MISRA C++:2023 RULE-4-1-3 “Undefined / critical unspecified behavior” package and wires in shared query implementations so existing logic can be reused across C, CERT C++, and MISRA C++ rule sets.

Changes:

  • Introduces a new rule_packages/cpp/Undefined.json package plus MISRA C++ RULE-4-1-3 query stubs and test scaffolding.
  • Refactors/centralizes two existing rule implementations into shared libraries (PossibleDataRaceBetweenThreadsShared.qll, DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.qll) and reuses them from C and C++ rule queries.
  • Updates CI workflows and adds change notes describing the refactors.

Reviewed changes

Copilot reviewed 42 out of 48 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
rule_packages/cpp/Undefined.json New C++ rule package definition for MISRA C++:2023 RULE-4-1-3 (undefined / critical unspecified behavior).
rule_packages/cpp/Freed.json Adds shared_implementation_short_name metadata for reuse of the array-delete mismatch query.
rule_packages/c/Concurrency9.json Adds shared_implementation_short_name metadata for reuse of the data-race query.
cpp/misra/test/rules/RULE-4-1-3/UndefinedBehaviorAudit.qlref Adds test reference for the MISRA C++ audit query wrapper.
cpp/misra/test/rules/RULE-4-1-3/UndefinedBehaviorAudit.expected Adds expected output file (currently empty) for the audit wrapper query.
cpp/misra/test/rules/RULE-4-1-3/UndefinedBehavior.qlref Adds test reference for the MISRA C++ query wrapper.
cpp/misra/test/rules/RULE-4-1-3/UndefinedBehavior.expected Adds expected output file (currently empty) for the wrapper query.
cpp/misra/test/rules/RULE-4-1-3/PossibleDataRaceBetweenThreads.testref Points MISRA C++ rule testing to the shared data-race implementation test.
cpp/misra/test/rules/RULE-4-1-3/CriticalUnspecifiedBehaviorAudit.qlref Adds test reference for the MISRA C++ audit query wrapper.
cpp/misra/test/rules/RULE-4-1-3/CriticalUnspecifiedBehaviorAudit.expected Adds expected output file (currently empty) for the audit wrapper query.
cpp/misra/test/rules/RULE-4-1-3/CriticalUnspecifiedBehavior.qlref Adds test reference for the MISRA C++ query wrapper.
cpp/misra/test/rules/RULE-4-1-3/CriticalUnspecifiedBehavior.expected Adds expected output file (currently empty) for the wrapper query.
cpp/misra/test/rules/RULE-4-1-3/ArrayDeletedThroughPointerOfIncorrectType.testref Points MISRA C++ rule testing to the shared array-delete mismatch implementation test.
cpp/misra/src/rules/RULE-4-1-3/UndefinedBehaviorAudit.ql Adds MISRA C++ audit wrapper query stub (no implementation).
cpp/misra/src/rules/RULE-4-1-3/UndefinedBehavior.ql Adds MISRA C++ wrapper query stub (no implementation).
cpp/misra/src/rules/RULE-4-1-3/PossibleDataRaceBetweenThreads.ql Adds MISRA C++ query that instantiates the shared data-race implementation.
cpp/misra/src/rules/RULE-4-1-3/CriticalUnspecifiedBehaviorAudit.ql Adds MISRA C++ audit wrapper query stub (no implementation).
cpp/misra/src/rules/RULE-4-1-3/CriticalUnspecifiedBehavior.ql Adds MISRA C++ wrapper query stub (no implementation).
cpp/misra/src/rules/RULE-4-1-3/ArrayDeletedThroughPointerOfIncorrectType.ql Adds MISRA C++ query that instantiates the shared array-delete mismatch implementation.
cpp/common/test/rules/possibledataracebetweenthreadsshared/test.cpp Adds a C++ shared-implementation test case for the data-race query.
cpp/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql Adds generated test driver query to instantiate the shared data-race implementation.
cpp/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.expected Adds expected results for the shared C++ data-race test.
cpp/common/test/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/test.cpp Minor formatting adjustment in the shared array-delete mismatch test source.
cpp/common/test/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.ql Adds generated test driver query to instantiate the shared array-delete mismatch implementation.
cpp/common/test/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.expected Adds expected results for the shared array-delete mismatch test.
cpp/common/src/codingstandards/cpp/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.qll New shared library implementing the possible data-race detection logic.
cpp/common/src/codingstandards/cpp/rules/donotdeleteanarraythroughapointeroftheincorrecttypeshared/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectTypeShared.qll New shared library implementing the array-delete type mismatch path-problem logic.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Undefined.qll New autogenerated exclusions/metadata wiring for the new Undefined package.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers the new Undefined package in global metadata wiring.
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.testref Redirects CERT EXP51-CPP testing to the shared implementation test.
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.qlref Removes direct test reference to the production EXP51-CPP query.
cpp/cert/test/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.expected Removes the old expected output (now covered by shared implementation tests).
cpp/cert/src/rules/EXP51-CPP/DoNotDeleteAnArrayThroughAPointerOfTheIncorrectType.ql Refactors the CERT query to instantiate the shared array-delete mismatch implementation.
change_notes/2026-03-13-share-array-delete-type-mismatch-query.md Change note for the shared refactor of EXP51-CPP array-delete mismatch logic.
change_notes/2026-03-09-possible-data-race-between-threads-shared.md Change note for the shared refactor of DIR-5-1 possible data-race logic.
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.testref Redirects MISRA C DIR-5-1 testing to the shared implementation test.
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.qlref Removes direct test reference to the production DIR-5-1 query.
c/misra/src/rules/DIR-5-1/PossibleDataRaceBetweenThreads.ql Refactors the MISRA C query to instantiate the shared data-race implementation.
c/common/test/rules/possibledataracebetweenthreadsshared/test.c Adds a C shared-implementation test case for the data-race query.
c/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql Adds generated test driver query to instantiate the shared data-race implementation (C config).
c/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.expected Adds expected results for the shared C data-race test.
.github/workflows/validate-query-test-case-formatting.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/validate-query-help.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/validate-query-formatting.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/validate-package-files.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/tooling-unit-tests.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/extra-rule-validation.yml Adds an explicit branch name to the workflow trigger list.
.github/workflows/codeql_unit_tests.yml Adds an explicit branch name to the workflow trigger list.

TStdFunctionCall(FunctionCall call) {
call.getTarget()
.hasName([
"setlocale", "tmpnam", "rand", "srand", "getenv", "getenv_s", "strok", "strerror",
srand(0); // NON-COMPLIANT
getenv("PATH"); // NON-COMPLIANT
getenv_s(NULL, NULL, 0, NULL); // NON-COMPLIANT
strtok("a", "b"); // NON-COMPLIANT
// Not all are defined in std:: in our stubs.
std::setlocale(LC_ALL, "C"); // NON-COMPLIANT
setlocale(LC_ALL, "C"); // NON-COMPLIANT
std::tmpnam(""); // NON-COMPLIANT
Comment on lines +12 to 13
- michaelrfairhurst/package-undefined-behavior

Comment on lines +12 to 13
- michaelrfairhurst/package-undefined-behavior

- main
- next
- "rc/**"
- michaelrfairhurst/package-undefined-behavior
Comment on lines +12 to 13
- michaelrfairhurst/package-undefined-behavior

- main
- "rc/**"
- next
- michaelrfairhurst/package-undefined-behavior
Comment on lines +18 to 20
- michaelrfairhurst/package-undefined-behavior


- main
- next
- "rc/**"
- michaelrfairhurst/package-undefined-behavior
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.

2 participants