From 60ba520e4f0b2467a4f019645c7fae971b84ef93 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 | 6 ++++-- test/testsuppressions.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index c3569e40d85..ac3dfb6ee67 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -33,6 +33,7 @@ #include #include #include // std::bind, std::placeholders +#include #include #include #include @@ -850,7 +851,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; @@ -886,7 +887,8 @@ 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 9460999adb1..f9ef1b8a8e8 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -2175,6 +2176,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 { @@ -2365,6 +2370,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 {