Skip to content

Commit

Permalink
Fix String.Concat with arrays containing null elements (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Oct 23, 2024
1 parent 95a9516 commit 0516bd1
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/CLR/CorLib/corlib_native_System_String.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
Expand Down Expand Up @@ -1157,23 +1157,24 @@ HRESULT Library_corlib_native_System_String::Concat(CLR_RT_StackFrame &stack, CL

for (int iStr = 0; iStr < num; iStr++)
{
_ASSERTE(ptrSrc->DataType() == DATATYPE_OBJECT);
_ASSERTE(FIMPLIES(ptrSrc->Dereference(), ptrSrc->Dereference()->DataType() == DATATYPE_STRING));

szTextSrc = ptrSrc->RecoverString();
if (szTextSrc)
if (ptrSrc->Dereference() != NULL && ptrSrc->Dereference()->DataType() == DATATYPE_STRING)
{
len = (CLR_UINT32)hal_strlen_s(szTextSrc);
szTextSrc = ptrSrc->RecoverString();

if (i == 0)
{
totLen += len;
}
else
if (szTextSrc)
{
memcpy(szTextDst, szTextSrc, len);
len = (CLR_UINT32)hal_strlen_s(szTextSrc);

szTextDst += len;
if (i == 0)
{
totLen += len;
}
else
{
memcpy(szTextDst, szTextSrc, len);

szTextDst += len;
}
}
}

Expand Down

0 comments on commit 0516bd1

Please sign in to comment.