From 6ccf4dd2224e4beb567365903249858a2ca00082 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sun, 18 Oct 2020 00:12:42 +0200 Subject: [PATCH] Limit nDecPlaces to a sensible value [-20, 20] Protect against callers using for example rtl_math_StringFormat_F with rtl_math_DecimalPlaces_Max in worst case.. Change-Id: I9f143df6ae67b22e7732547c0f7a53b498caf2b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104472 Reviewed-by: Eike Rathke Tested-by: Jenkins --- sal/rtl/math.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index b7dc1cbbc7f0..fe81f4c5a7f7 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -433,6 +433,12 @@ void doubleToString(typename T::String ** pResult, break; } + // Too large values for nDecPlaces make no sense; it might also be + // rtl_math_DecimalPlaces_Max was passed with rtl_math_StringFormat_F or + // others, but we don't want to allocate/deallocate 2GB just to fill it + // with trailing '0' characters.. + nDecPlaces = std::max(std::min(nDecPlaces, 20), -20); + sal_Int32 nDigits = nDecPlaces + 1; if (eFormat == rtl_math_StringFormat_F)