sc/source/core/inc/interpre.hxx | 16 ++++++++++++++++ sc/source/core/tool/interpr1.cxx | 5 ++++- sc/source/core/tool/interpr8.cxx | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 10 deletions(-)
New commits: commit ca844d61ea19c9b2096db6047110ec0257d817bb Author: Eike Rathke <er...@redhat.com> AuthorDate: Fri Oct 26 11:12:30 2018 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri Oct 26 16:34:54 2018 +0200 Use CheckStringResultLen() also for CONCATENATE(), CONCAT() and TEXTJOIN() Change-Id: Ifbc2b127998e037be3f014bebf8721bef15ef53b Reviewed-on: https://gerrit.libreoffice.org/62385 Tested-by: Jenkins Reviewed-by: Eike Rathke <er...@redhat.com> diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index c7bcfb9a7d91..7608098d53bb 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -484,6 +484,11 @@ private: // Check for String overflow of rResult+rAdd and set error and erase rResult // if so. Return true if ok, false if overflow inline bool CheckStringResultLen( OUString& rResult, const OUString& rAdd ); + + // Check for String overflow of rResult+rAdd and set error and erase rResult + // if so. Return true if ok, false if overflow + inline bool CheckStringResultLen( OUStringBuffer& rResult, const OUString& rAdd ); + // Set error according to rVal, and set rVal to 0.0 if there was an error. inline void TreatDoubleError( double& rVal ); // Lookup using ScLookupCache, @returns true if found and result address @@ -1112,6 +1117,17 @@ inline bool ScInterpreter::CheckStringResultLen( OUString& rResult, const OUStri return true; } +inline bool ScInterpreter::CheckStringResultLen( OUStringBuffer& rResult, const OUString& rAdd ) +{ + if (rAdd.getLength() > kScInterpreterMaxStrLen - rResult.getLength()) + { + SetError( FormulaError::StringOverflow ); + rResult = OUStringBuffer(); + return false; + } + return true; +} + inline void ScInterpreter::TreatDoubleError( double& rVal ) { if ( !::rtl::math::isFinite( rVal ) ) diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index a0ae2d5ded14..6c3012ad2ad9 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -9456,7 +9456,10 @@ void ScInterpreter::ScConcat() while( nParamCount-- > 0) { OUString aStr = GetString().getString(); - aRes = aStr + aRes; + if (CheckStringResultLen( aRes, aStr)) + aRes = aStr + aRes; + else + break; } PushString( aRes ); } diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx index 647a450afa35..8fad91109fbc 100644 --- a/sc/source/core/tool/interpr8.cxx +++ b/sc/source/core/tool/interpr8.cxx @@ -1359,7 +1359,11 @@ void ScInterpreter::ScConcat_MS() { case svString: case svDouble: - aResBuf.append( GetString().getString() ); + { + const OUString& rStr = GetString().getString(); + if (CheckStringResultLen( aResBuf, rStr)) + aResBuf.append( rStr); + } break; case svSingleRef : { @@ -1374,7 +1378,9 @@ void ScInterpreter::ScConcat_MS() { svl::SharedString aSS; GetCellString( aSS, aCell); - aResBuf.append( aSS.getString()); + const OUString& rStr = aSS.getString(); + if (CheckStringResultLen( aResBuf, rStr)) + aResBuf.append( rStr); } } } @@ -1415,7 +1421,9 @@ void ScInterpreter::ScConcat_MS() { svl::SharedString aSS; GetCellString( aSS, aCell); - aResBuf.append( aSS.getString()); + const OUString& rStr = aSS.getString(); + if (CheckStringResultLen( aResBuf, rStr)) + aResBuf.append( rStr); } } } @@ -1440,11 +1448,19 @@ void ScInterpreter::ScConcat_MS() for (SCSIZE k = 0; k < nR; k++ ) { if ( pMat->IsStringOrEmpty( j, k ) ) - aResBuf.append( pMat->GetString( j, k ).getString() ); + { + const OUString& rStr = pMat->GetString( j, k ).getString(); + if (CheckStringResultLen( aResBuf, rStr)) + aResBuf.append( rStr); + } else { if ( pMat->IsValue( j, k ) ) - aResBuf.append( pMat->GetString( *pFormatter, j, k ).getString() ); + { + const OUString& rStr = pMat->GetString( *pFormatter, j, k ).getString(); + if (CheckStringResultLen( aResBuf, rStr)) + aResBuf.append( rStr); + } } } } @@ -1617,7 +1633,8 @@ void ScInterpreter::ScTextJoin_MS() } else bFirst = false; - aResBuf.append( aStr ); + if (CheckStringResultLen( aResBuf, aStr)) + aResBuf.append( aStr ); } } break; @@ -1653,7 +1670,8 @@ void ScInterpreter::ScTextJoin_MS() } else bFirst = false; - aResBuf.append( aStr ); + if (CheckStringResultLen( aResBuf, aStr)) + aResBuf.append( aStr ); } } break; @@ -1712,7 +1730,8 @@ void ScInterpreter::ScTextJoin_MS() } else bFirst = false; - aResBuf.append( aStr ); + if (CheckStringResultLen( aResBuf, aStr)) + aResBuf.append( aStr ); } } } @@ -1761,7 +1780,8 @@ void ScInterpreter::ScTextJoin_MS() } else bFirst = false; - aResBuf.append( aStr ); + if (CheckStringResultLen( aResBuf, aStr)) + aResBuf.append( aStr ); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits