From 5256aa31156e43aa00e2a36f4a50f2af98212ed1 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Thu, 22 Oct 2026 19:27:09 +0530 Subject: [PATCH] fix polyspace +N range overflow in inline suppressions --- lib/suppressions.cpp | 5 +++-- test/testsuppressions.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 0089510c86f..0de87f2493f 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -32,6 +32,7 @@ #include // std::isdigit, std::isalnum, etc #include #include +#include #include #include #include @@ -885,7 +886,7 @@ std::list polyspace::Parser::parse(const std::stri if (rangeValue > 0) { suppr.type = SuppressionList::Type::block; suppr.lineBegin = line; - suppr.lineEnd = line + rangeValue; + suppr.lineEnd = (rangeValue > std::numeric_limits::max() - line) ? std::numeric_limits::max() : (line + rangeValue); } else if (polyspaceKind == polyspace::CommentKind::Regular) suppr.type = SuppressionList::Type::unique; @@ -921,7 +922,7 @@ int polyspace::Parser::parseRange(const std::string& comment, std::string::size_ int ret = std::stoi(range); pos = endpos; return ret; - } catch (const std::invalid_argument &) {} + } catch (const std::invalid_argument &) {} catch (const std::out_of_range &) {} return 0; } diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index fbdcb6307e5..b5d69e9c84b 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -2206,6 +2207,10 @@ class TestSuppressions : public TestFixture { pos = 0; ASSERT_EQUALS(0, polyspace::Parser::parseRange(" +A ",pos)); ASSERT_EQUALS(1U, pos); + + pos = 0; + ASSERT_EQUALS(0, polyspace::Parser::parseRange(" +99999999999 ",pos)); + ASSERT_EQUALS(1U, pos); } void polyspaceParseIds() const { @@ -2396,6 +2401,12 @@ class TestSuppressions : public TestFixture { { "/* polyspace +3 MISRA2012 : 2.7 */", 1 }, { { "premium-misra-c-2012-2.7", 1, "", SuppressionList::Type::block, 1, 4 } } ); + + testPolyspaceSuppression( + "", "--misra-c-2012", + { "/* polyspace +2147483647 MISRA2012 : 2.7 */", 2 }, + { { "premium-misra-c-2012-2.7", 2, "", SuppressionList::Type::block, 2, std::numeric_limits::max() } } + ); } void polyspaceBlock() const {