summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-12-02 08:14:51 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-12-03 09:13:38 +0100
commitba7db98cca3d8516697c94ef0d6af27db9e1655e (patch)
tree8d00c89541570a81127bbc7d82ffe88eb84dbd2d
parent5c7c54332f779afb847ece6396637e17957fc0d1 (diff)
Use strncpy to avoid overflow and fill the rest with nulls
Change-Id: I29c427b87aa87af3236bd6e1a7e9e08e6f470bf6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126227 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--vcl/source/treelist/transfer.cxx7
1 files changed, 4 insertions, 3 deletions
diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx
index 81c99653578f..4561535d0291 100644
--- a/vcl/source/treelist/transfer.cxx
+++ b/vcl/source/treelist/transfer.cxx
@@ -784,10 +784,11 @@ bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk,
case SotClipboardFormatId::NETSCAPE_BOOKMARK:
{
Sequence< sal_Int8 > aSeq( 2048 );
+ char* pSeq = reinterpret_cast< char* >( aSeq.getArray() );
- memset( aSeq.getArray(), 0, 2048 );
- strcpy( reinterpret_cast< char* >( aSeq.getArray() ), OUStringToOString(rBmk.GetURL(), eSysCSet).getStr() );
- strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, OUStringToOString(rBmk.GetDescription(), eSysCSet).getStr() );
+ // strncpy fills the rest with nulls, as we need
+ strncpy( pSeq, OUStringToOString(rBmk.GetURL(), eSysCSet).getStr(), 1024 );
+ strncpy( pSeq + 1024, OUStringToOString(rBmk.GetDescription(), eSysCSet).getStr(), 1024 );
maAny <<= aSeq;
}