Skip to content

Add MISRA C:2025 Addendum 5 CWE tags to MISRA C queries - #1229

Draft
mbaluda wants to merge 1 commit into
misra-c-2025-developmentfrom
mbaluda/misra-c-2025-cwe-tags
Draft

mbaluda wants to merge 1 commit into
misra-c-2025-developmentfrom
mbaluda/misra-c-2025-cwe-tags

Conversation

@mbaluda

@mbaluda mbaluda commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds CWE tags (external/cwe/cwe-NNN, the convention used by CodeQL default suites) to implemented MISRA C queries, based on the guideline-to-CWE mapping in MISRA C:2025 Addendum 5 (memory safety, CWE-1399).

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 number here
  • Queries have been modified for the following rules:
    • Metadata only (CWE tags): RULE-1-3, RULE-9-1, RULE-11-1, RULE-11-2, RULE-11-3, RULE-11-4, RULE-11-5, RULE-11-6, RULE-18-1, RULE-18-9, RULE-19-2, RULE-21-3, RULE-21-6, RULE-21-17, RULE-21-18, RULE-22-2, DIR-4-7, DIR-4-11, DIR-4-12

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!)

Tag implemented MISRA C queries with the CWE associations listed in
MISRA C:2025 Addendum 5 (memory safety), using the CodeQL
external/cwe/cwe-NNN convention. Allow these tags in the rule package
schema via a three-digit pattern and regenerate query metadata.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mbaluda
mbaluda marked this pull request as ready for review November 26, 2026 14:02
Copilot AI adaptive review requested due to automatic review settings November 26, 2026 14:02
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main November 26, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active moderate and critical findings remain around schema compatibility, incomplete suite query coverage, and unsafe path validation that could execute files outside the repository.

3 open issues
What changed in this PR

This pull request adds MISRA C:2025 support and Addendum 5 CWE metadata to MISRA C queries, while updating edition-aware suite selection, supported-rule reporting, test tooling, recategorization behavior, and related documentation.

Changes:

  • Adds CWE tags, MISRA C:2025 package metadata, schemas, rule mappings, and suite definitions.
  • Updates release, matrix-testing, test-reference, and supported-rule tooling for multiple MISRA C editions.
  • Adds MISRA C:2025 query wrappers, shared analysis logic, recategorization support, regression tests, and documentation.
File Description
scripts/​verify_rule_package_consistency.py Validates MISRA C edition tags and package consistency.
scripts/​verify_rule_package_consistency_test.py Tests edition-tag consistency validation.
scripts/​validate-amendments-csv.py Allows cross-edition MISRA C amendment mappings.
scripts/​release/​generate_release_notes.py Adds MISRA C:2025 release-note handling.
scripts/​release/​create_supported_rules_list.py Computes edition-specific supported-rule lists.
scripts/​release/​create_supported_rules_list_test.py Tests supported-rule generation across editions.
scripts/​PSCodingStandards/​README.md Documents reusable test references and MISRA C:2025 suite behavior.
scripts/​PSCodingStandards/​Get-TestFile.ps1 Resolves direct and referenced runnable test files.
scripts/​PSCodingStandards/​Get-TestDirectory.ps1 Derives test directories from resolved test files.
scripts/​PSCodingStandards/​Get-RulesInPackageAndSuite.ps1 Tracks applicable suites for queries.
scripts/​PSCodingStandards/​Get-RuleForPath.ps1 Matches source, wrapper, and resolved fixture paths.
scripts/​PSCodingStandards/​Config.ps1 Defines MISRA C:2025 suite inclusion and legacy exclusions.
scripts/​matrix_testing/​Get-TestFile.Tests.ps1 Adds matrix-tooling regression coverage.
scripts/​matrix_testing/​CreateMatrixTestReport.ps1 Runs matrix tests using resolved test references and applicable suites.
scripts/​generate_rules/​generate_package_files.py Supports reusable test references and edition-aware package generation.
scripts/​generate_rules/​coding_standards_utils.py Preserves query tags and reuses MISRA C help templates.
schemas/​rule-package.schema.json Adds MISRA C:2025 metadata and CWE tag schema support.
rules.csv Updates MISRA C:2025 rule ownership and obligation metadata.
rule_packages/​c/​Static.json Marks legacy static-array query coverage.
rule_packages/​c/​Statements5.json Adds MISRA C:2025 Rule 15.5 package metadata.
rule_packages/​c/​Preprocessor4.json Adds MISRA C:2025 reserved-macro package metadata.
rule_packages/​c/​Pointers1.json Adds pointer-rule CWE metadata and current rule information.
rule_packages/​c/​OutOfBounds.json Adds CWE metadata for bounds queries.
rule_packages/​c/​Memory2.json Adds memory-safety CWE metadata.
rule_packages/​c/​Language3.json Adds MISRA C:2025 language-extension metadata and legacy tagging.
rule_packages/​c/​InvalidMemory3.json Adds CWE-562 metadata.
rule_packages/​c/​InvalidMemory1.json Adds uninitialized-memory CWE metadata.
rule_packages/​c/​Declarations6.json Marks shared query coverage as applicable to MISRA C:2025.
rule_packages/​c/​Declarations5.json Adds planned MISRA C:2025 declaration rules.
rule_packages/​c/​Declarations1.json Adds MISRA C:2025 Rule 5.10 metadata.
rule_packages/​c/​DeadCode2.json Standardizes the MISRA strict-suite tag.
rule_packages/​c/​Contracts7.json Adds planned MISRA C:2025 Rule 19.3 metadata.
rule_packages/​c/​Contracts6.json Marks array-contract coverage as applicable to MISRA C:2025.
rule_packages/​c/​Contracts.json Adds CWE metadata for contract and library checks.
rule_packages/​c/​Concurrency6.json Standardizes the MISRA audit-suite tag.
rule_packages/​c/​Banned.json Adds CWE and MISRA C:2025 metadata for banned-function queries.
docs/​user_manual.md Documents MISRA C:2025 suites and Disapplied rules.
docs/​design/​guideline_recategorization.md Documents Disapplied guideline recategorization transitions.
cpp/​common/​test/​guideline_recategorizations/​DisappliedRecategorizations.ql Tests Disapplied recategorization behavior.
cpp/​common/​test/​guideline_recategorizations/​DisappliedRecategorizations.expected Records Disapplied recategorization expectations.
cpp/​common/​src/​codingstandards/​cpp/​guideline_recategorizations/​ListGuidelineRecategorizations.ql Reports original recategorization categories.
cpp/​common/​src/​codingstandards/​cpp/​guideline_recategorizations/​GuidelineRecategorizations.qll Implements multi-query and Disapplied recategorization logic.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​RuleMetadata.qll Applies recategorizations only to applicable queries.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Statements5.qll Registers the MISRA C:2025 Rule 15.5 query.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Preprocessor4.qll Registers the MISRA C:2025 reserved-macro query.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Language3.qll Registers the MISRA C:2025 language-extension query.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Declarations1.qll Registers the MISRA C:2025 reserved-identifier query.
change_notes/​2026-11-18-standardize-misra-suite-tags.md Records MISRA suite-tag standardization changes.
change_notes/​2026-11-03-misra-c-2025-query-updates.md Records MISRA C:2025 query and suite changes.
c/​misra/​test/​rules/​RULE-5-10/​ReservedIdentifierDeclared.testref Reuses reserved-identifier test coverage.
c/​misra/​test/​rules/​RULE-21-8/​test.c Adds assertion and termination test cases.
c/​misra/​test/​rules/​RULE-21-8/​TerminationFunctionsOfStdlibhUsed.expected Adds assertion alert expectations.
c/​misra/​test/​rules/​RULE-21-8/​qualified-names/​test.cpp Tests qualified termination-function names.
c/​misra/​test/​rules/​RULE-21-8/​qualified-names/​TerminationFunctionsOfStdlibhUsed.qlref References the qualified-name termination query.
c/​misra/​test/​rules/​RULE-21-8/​qualified-names/​TerminationFunctionsOfStdlibhUsed.expected Records qualified-name query expectations.
c/​misra/​test/​rules/​RULE-21-8/​qualified-names/​headers/​stdlib.h Supplies qualified-library test declarations.
c/​misra/​test/​rules/​RULE-21-1/​ReservedMacroName.qlref References the legacy reserved-macro fixture.
c/​misra/​test/​rules/​RULE-21-1/​ReservedMacroName.expected Records legacy reserved-macro expectations.
c/​misra/​test/​rules/​RULE-20-15/​ReservedMacroName.testref Reuses the legacy reserved-macro test.
c/​misra/​test/​rules/​RULE-17-5/​UseOfArrayStatic_MISRA_C_2012.qlref Preserves the legacy array-static test reference.
c/​misra/​test/​rules/​RULE-17-5/​UseOfArrayStatic_MISRA_C_2012.expected Records legacy array-static expectations.
c/​misra/​test/​rules/​RULE-17-5/​test_MISRA_C_2025.c Adds array-contract coverage for MISRA C:2025.
c/​misra/​test/​rules/​RULE-17-5/​ArrayFunctionArgumentNumberOfElements.expected Adds current-edition array-contract expectations.
c/​misra/​test/​rules/​RULE-17-3/​test.c Updates implicit-declaration fixture options.
c/​misra/​test/​rules/​RULE-17-3/​test_c99.c Adds C99 implicit-declaration coverage.
c/​misra/​test/​rules/​RULE-17-3/​FunctionDeclaredImplicitly.expected Adds C99 alert expectations.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​test.c Tests the default Disapplied behavior.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​SinglePointOfExit.qlref References the unconfigured Disapplied query.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​SinglePointOfExit.expected Records empty default results.
c/​misra/​test/​rules/​RULE-15-5/​SinglePointOfExit.qlref References the recategorized Rule 15.5 query.
c/​misra/​test/​rules/​RULE-15-5/​SinglePointOfExit.expected Records recategorized Rule 15.5 alerts.
c/​misra/​test/​rules/​RULE-15-5/​coding-standards.yml Configures Rule 15.5 recategorization.
c/​misra/​test/​rules/​RULE-15-5/​coding-standards.xml Stores generated recategorization configuration.
c/​misra/​test/​rules/​RULE-1-2/​LanguageExtensionsShouldBeMinimized.qlref References the minimized-extension query.
c/​misra/​test/​rules/​RULE-1-2/​LanguageExtensionsShouldBeMinimized.expected Records language-extension expectations.
c/​misra/​test/​rules/​DIR-1-2/​LanguageExtensionsShouldBeMinimized.testref Reuses the legacy language-extension fixture.
c/​misra/​src/​rules/​RULE-9-1/​ObjectWithAutoStorageDurationReadBeforeInit.ql Adds uninitialized-memory CWE metadata.
c/​misra/​src/​rules/​RULE-5-10/​ReservedIdentifierDeclared.ql Adds the MISRA C:2025 Rule 5.10 query wrapper.
c/​misra/​src/​rules/​RULE-22-2/​OnlyFreeMemoryAllocatedDynamicallyMisra.ql Adds memory-management CWE metadata.
c/​misra/​src/​rules/​RULE-21-8/​TerminationMacrosOfStdlibhUsed.ql Marks the termination-macro query for MISRA C:2025.
c/​misra/​src/​rules/​RULE-21-8/​TerminationFunctionsOfStdlibhUsed.ql Adds assertion termination detection and CWE metadata.
c/​misra/​src/​rules/​RULE-21-6/​StandardLibraryInputoutputFunctionsUsed.ql Adds library-I/O CWE metadata.
c/​misra/​src/​rules/​RULE-21-3/​MemoryAllocDeallocFunctionsOfStdlibhUsed.ql Adds allocation-related CWE metadata.
c/​misra/​src/​rules/​RULE-21-2/​DoNotDeclareAReservedIdentifier.ql Marks the old reserved-identifier query as legacy.
c/​misra/​src/​rules/​RULE-21-18/​StringLibrarySizeArgumentOutOfBounds.ql Adds string-size CWE metadata.
c/​misra/​src/​rules/​RULE-21-17/​StringFunctionPointerArgumentOutOfBounds.ql Adds string-pointer CWE metadata.
c/​misra/​src/​rules/​RULE-21-1/​DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql Refactors reserved-macro detection and marks the query as legacy.
c/​misra/​src/​rules/​RULE-20-15/​ReservedMacroName.ql Adds the MISRA C:2025 Rule 20.15 query wrapper.
c/​misra/​src/​rules/​RULE-2-8/​UnusedObjectDefinitionStrict.ql Standardizes the strict-suite tag.
c/​misra/​src/​rules/​RULE-19-2/​UnionKeywordShouldNotBeUsed.ql Adds CWE-188 metadata.
c/​misra/​src/​rules/​RULE-18-9/​ModifiableLValueSubscriptedWithTemporaryLifetime.ql Adds CWE-562 metadata.
c/​misra/​src/​rules/​RULE-18-9/​ArrayToPointerConversionOfTemporaryObject.ql Adds CWE-562 metadata.
c/​misra/​src/​rules/​RULE-18-1/​PointerAndDerivedPointerMustAddressSameArray.ql Adds pointer-bounds CWE metadata.
c/​misra/​src/​rules/​RULE-17-6/​UseOfArrayStatic.ql Marks the array-static query as legacy.
c/​misra/​src/​rules/​RULE-17-5/​ArrayFunctionArgumentNumberOfElements.ql Marks array-contract coverage as applicable to MISRA C:2025.
c/​misra/​src/​rules/​RULE-17-3/​FunctionDeclaredImplicitly.ql Marks implicit-declaration coverage as applicable to MISRA C:2025.
c/​misra/​src/​rules/​RULE-15-5/​SinglePointOfExit.ql Adds the Disapplied MISRA C:2025 Rule 15.5 query.
c/​misra/​src/​rules/​RULE-15-5/​FunctionReturnCondition.ql Extracts shared exit-analysis logic and marks the old query as legacy.
c/​misra/​src/​rules/​RULE-11-6/​CastBetweenPointerToVoidAndArithmeticType.ql Adds pointer-conversion CWE metadata.
c/​misra/​src/​rules/​RULE-11-5/​ConversionFromPointerToVoidIntoPointerToObject.ql Adds pointer-conversion CWE metadata.
c/​misra/​src/​rules/​RULE-11-4/​ConversionBetweenPointerToObjectAndIntegerType.ql Adds pointer and integer CWE metadata.
c/​misra/​src/​rules/​RULE-11-3/​CastBetweenObjectPointerAndDifferentObjectType.ql Adds pointer-conversion CWE metadata.
c/​misra/​src/​rules/​RULE-11-2/​ConversionBetweenIncompleteTypePointerAndOtherType.ql Adds pointer-conversion CWE metadata.
c/​misra/​src/​rules/​RULE-11-1/​ConversionBetweenFunctionPointerAndOtherType.ql Adds function-pointer CWE metadata.
c/​misra/​src/​rules/​RULE-1-3/​OccurrenceOfUndefinedBehavior.ql Adds undefined-behavior CWE metadata.
c/​misra/​src/​rules/​RULE-1-2/​LanguageExtensionsShouldNotBeUsed.ql Marks the old language-extension query as legacy.
c/​misra/​src/​rules/​DIR-5-3/​BannedDynamicThreadCreation.ql Standardizes the audit-suite tag.
c/​misra/​src/​rules/​DIR-4-7/​FunctionErrorInformationUntested.ql Adds unchecked-error CWE metadata.
c/​misra/​src/​rules/​DIR-4-12/​StdLibDynamicMemoryAllocationUsed.ql Adds dynamic-memory CWE metadata.
c/​misra/​src/​rules/​DIR-4-11/​LowPrecisionPeriodicTrigonometricFunctionCall.ql Adds math-library CWE metadata.
c/​misra/​src/​rules/​DIR-4-11/​CheckMathLibraryFunctionParameters.ql Adds math-library CWE metadata.
c/​misra/​src/​rules/​DIR-1-2/​LanguageExtensionsShouldBeMinimized.ql Adds the MISRA C:2025 language-extension query.
c/​misra/​src/​qlpack.yml Updates the MISRA C pack description.
c/​misra/​src/​codingstandards/​c/​misra/​SinglePointOfExit.qll Provides shared single-exit analysis.
c/​misra/​src/​codingstandards/​c/​misra/​ReservedMacroNames.qll Provides shared reserved-macro analysis.
c/​misra/​src/​codeql-suites/​misra-default.qls Updates the deprecated suite description.
c/​misra/​src/​codeql-suites/​misra-c-strict.qls Targets MISRA C:2025 strict analysis.
c/​misra/​src/​codeql-suites/​misra-c-required.qls Targets MISRA C:2025 required analysis.
c/​misra/​src/​codeql-suites/​misra-c-mandatory.qls Targets MISRA C:2025 mandatory analysis.
c/​misra/​src/​codeql-suites/​misra-c-default.qls Makes MISRA C:2025 the default suite.
c/​misra/​src/​codeql-suites/​misra-c-audit.qls Targets MISRA C:2025 audit analysis.
c/​misra/​src/​codeql-suites/​misra-c-advisory.qls Targets MISRA C:2025 advisory analysis.
c/​misra/​src/​codeql-suites/​misra-c-2023.qls Preserves the older MISRA C edition suite.
amendments.csv Records MISRA C:2025 rule changes and mappings.
.github/​workflows/​tooling-unit-tests.yml Runs the new Python and PowerShell tooling checks.

Review effort: Lite (adaptive)

Comment on lines +48 to +53
if ([IO.Path]::IsPathRooted($reference.Trim())) {
throw "Test reference must be repository-relative: $referenceFile"
}

$repositoryRoot = Get-RepositoryRoot
$testFile = Join-Path $repositoryRoot $reference.Trim()
Comment on lines +361 to +363
"external/misra/c/2025",
"external/misra/default-disabled",
"external/misra/legacy",
Comment on lines +38 to +44
$queries | Add-Member -NotePropertyName __applicable_suites -NotePropertyValue @($Suite)
foreach ($targetSuite in $SUITE_DEFINITIONS.Keys) {
$definition = $SUITE_DEFINITIONS[$targetSuite]
if ($definition.IncludeSuites -contains $Suite) {
$queries | Where-Object {
-not ($_.tags | Where-Object { $definition.ExcludeTags -contains $_ })
} | ForEach-Object { $_.__applicable_suites += $targetSuite }
@mbaluda
mbaluda marked this pull request as draft November 26, 2026 14:43
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development November 26, 2026 14:44
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main November 26, 2026 14:44
@mbaluda mbaluda closed this Nov 26, 2026
@mbaluda mbaluda reopened this Nov 26, 2026
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development November 26, 2026 14: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.

2 participants