From 63c56dd73066fe57e2ac34a5ef90256836d8b97e Mon Sep 17 00:00:00 2001 From: Mikhail Khachayants Date: Sun, 20 Oct 2024 13:19:49 +0300 Subject: [PATCH] Prevent potential division by zero --- include/valijson/constraints/concrete_constraints.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/valijson/constraints/concrete_constraints.hpp b/include/valijson/constraints/concrete_constraints.hpp index 536f7ed..8ba30e2 100644 --- a/include/valijson/constraints/concrete_constraints.hpp +++ b/include/valijson/constraints/concrete_constraints.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -784,6 +785,11 @@ public: void setDivisor(double newValue) { + if (!std::isfinite(newValue) || newValue <= 0.0) { + throwRuntimeError( + "Divisor for 'multipleOf' or 'divisibleBy' must be positive"); + } + m_value = newValue; } @@ -813,6 +819,11 @@ public: void setDivisor(int64_t newValue) { + if (newValue <= 0) { + throwRuntimeError( + "Divisor for 'multipleOf' or 'divisibleBy' must be positive"); + } + m_value = newValue; }