From ac49efa23fc7c1d0e426b228d2206b57ebc95ce5 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 18 Jul 2018 18:30:14 +0100 Subject: [PATCH] Apply changes from https://github.com/boostorg/regex/pull/16 --- include/boost/regex/v4/regex_workaround.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/boost/regex/v4/regex_workaround.hpp b/include/boost/regex/v4/regex_workaround.hpp index f245f90d..35eafc25 100644 --- a/include/boost/regex/v4/regex_workaround.hpp +++ b/include/boost/regex/v4/regex_workaround.hpp @@ -198,9 +198,10 @@ namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ const char *strSource ) { - if(std::strlen(strSource)+1 > sizeInBytes) + std::size_t lenSourceWithNull = std::strlen(strSource) + 1; + if (lenSourceWithNull > sizeInBytes) return 1; - std::strcpy(strDestination, strSource); + std::memcpy(strDestination, strSource, lenSourceWithNull); return 0; } inline std::size_t strcat_s( @@ -209,9 +210,11 @@ namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ const char *strSource ) { - if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes) + std::size_t lenSourceWithNull = std::strlen(strSource) + 1; + std::size_t lenDestination = std::strlen(strDestination); + if (lenSourceWithNull + lenDestination > sizeInBytes) return 1; - std::strcat(strDestination, strSource); + std::memcpy(strDestination + lenDestination, strSource, lenSourceWithNull); return 0; }