diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-05-23 23:57:50 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2017-06-07 11:48:57 +0200 |
commit | ef117cad3a13fda0932bd3da6c032f3499eb9069 (patch) | |
tree | 8d305164db0b8425cb48db6e8683c3fddc543bd0 /include | |
parent | 9d1edef89b5a8cb333dfdd12631a9fa2ce3d482d (diff) |
tdf#108039: check for nullptr in rtl_uString and OUString
rtl_[u]String_newConcat now checks allocation result to return
early and avoid SIGSEGV. Other functions are not modified, to
keep old behavior relying on allocation success and crashing
early on OOM to avoid added overhead in performance-critical
places.
OUString operator+= now checks rtl_uString_newConcat result and
throws std::bad_alloc on failure, to specifically address BASIC
problem. It keeps strong exception guarantee of leaving this'
state unaltered.
Concatenation in BASIC now checks for bad string allocation
(previously SIGSEGV was generated).
Unit test included.
Change-Id: I1513311d3d58eac43b2d2ec9a230e22dff0b4245
Reviewed-on: https://gerrit.libreoffice.org/37965
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/ustring.hxx | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 8b1cd3a1404f..e4dfe8d8346d 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -519,13 +519,21 @@ public: Append a string to this string. @param str a OUString. + + @exception std::bad_alloc is thrown if an out-of-memory condition occurs */ OUString & operator+=( const OUString & str ) #if defined LIBO_INTERNAL_ONLY && HAVE_CXX11_REF_QUALIFIER & #endif { - rtl_uString_newConcat( &pData, pData, str.pData ); + rtl_uString* pNewData = NULL; + rtl_uString_newConcat( &pNewData, pData, str.pData ); + if (pNewData == NULL) { + throw std::bad_alloc(); + } + rtl_uString_assign(&pData, pNewData); + rtl_uString_release(pNewData); return *this; } #if defined LIBO_INTERNAL_ONLY && HAVE_CXX11_REF_QUALIFIER |