Skip to content

Add critical unspecified behavior for signed integer overflow#1082

Open
MichaelRFairhurst wants to merge 2 commits intomichaelrfairhurst/package-undefined-behaviorfrom
michaelrfairhurst/package-undefined-signed-integer-overflow
Open

Add critical unspecified behavior for signed integer overflow#1082
MichaelRFairhurst wants to merge 2 commits intomichaelrfairhurst/package-undefined-behaviorfrom
michaelrfairhurst/package-undefined-signed-integer-overflow

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:
    • 4-1-3
  • Queries have been modified for the following rules:
    • INT32-C

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

@MichaelRFairhurst MichaelRFairhurst marked this pull request as ready for review March 18, 2026 07:53
Copilot AI review requested due to automatic review settings March 18, 2026 07:53
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

This PR adds a new MISRA C++ 2023 RULE-4-1-3 query for signed integer overflow/underflow by reusing (and introducing) a shared CodeQL implementation that is also used to refactor the existing CERT C INT32-C rule query.

Changes:

  • Added a new MISRA C++ query (RULE-4-1-3) for signed integer overflow using a shared implementation.
  • Refactored CERT C INT32-C to use the new shared library module.
  • Added/updated shared-library unit tests and updated package/exclusion metadata plus a change note.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rule_packages/cpp/Undefined.json Adds the new RULE-4-1-3 query entry for signed integer overflow.
rule_packages/c/IntegerOverflow.json Links INT32-C’s query to the shared implementation via shared_implementation_short_name.
cpp/misra/test/rules/RULE-4-1-3/SignedIntegerOverflow.testref Points MISRA RULE-4-1-3 testing to the shared test suite.
cpp/misra/src/rules/RULE-4-1-3/SignedIntegerOverflow.ql Adds the new MISRA query wrapper that instantiates the shared module.
cpp/common/test/rules/signedintegeroverflowshared/test.cpp Adds C++ test cases (COMPLIANT/NON_COMPLIANT) for the shared overflow logic.
cpp/common/test/rules/signedintegeroverflowshared/SignedIntegerOverflowShared.ql Test driver query for the shared module (generated).
cpp/common/test/rules/signedintegeroverflowshared/SignedIntegerOverflowShared.expected Expected results for the C++ shared-module tests.
cpp/common/src/codingstandards/cpp/rules/signedintegeroverflowshared/SignedIntegerOverflowShared.qll Introduces the reusable shared query logic for signed integer overflow/underflow.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Undefined.qll Registers the new MISRA query in the Undefined package metadata/exclusions mapping.
change_notes/2026-03-13-share-signed-integer-overflow-query.md Documents the refactor for INT32-C into a shared library for reuse.
c/common/test/rules/signedintegeroverflowshared/test.c Adds C test cases for the shared overflow logic.
c/common/test/rules/signedintegeroverflowshared/SignedIntegerOverflowShared.ql Test driver query for the shared module in the C test suite (generated).
c/common/test/rules/signedintegeroverflowshared/SignedIntegerOverflowShared.expected Fixes/aligns expected results formatting for the C shared-module tests.
c/cert/test/rules/INT32-C/SignedIntegerOverflow.testref Points INT32-C testing to the shared test suite.
c/cert/test/rules/INT32-C/SignedIntegerOverflow.qlref Removes the old direct test reference in favor of .testref.
c/cert/src/rules/INT32-C/SignedIntegerOverflow.ql Refactors INT32-C query to instantiate the shared module.

}

void test_sub_precheck(signed int i1, signed int i2) {
// Style recomended by CERT
Comment on lines +4 to +5
* The multiplication of two signed integers can lead to underflow or overflow and
* therefore undefined behavior.
Comment on lines +74 to +77
"description": "Signed integer overflow or underflow from arithmetic operations results in critical unspecified behavior.",
"kind": "problem",
"name": "Signed integer overflow leads to critical unspecified behavior",
"precision": "medium",
Comment on lines +3 to +5
* @name RULE-4-1-3: Signed integer overflow leads to critical unspecified behavior
* @description Signed integer overflow or underflow from arithmetic operations results in critical
* unspecified 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