From: Jeff Schwartz Date: Wed, 21 Mar 2018 20:07:00 +0000 (-0700) Subject: null terminate the converted LPStr at the right index (#17079) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e99c94d3108257c61d5690d15662c020a2b5ba07;p=platform%2Fupstream%2Fcoreclr.git null terminate the converted LPStr at the right index (#17079) --- diff --git a/src/vm/olevariant.cpp b/src/vm/olevariant.cpp index 95c0b9b0cc..35936bbc5a 100644 --- a/src/vm/olevariant.cpp +++ b/src/vm/olevariant.cpp @@ -2310,8 +2310,9 @@ void OleVariant::MarshalLPSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleAr ThrowOutOfMemory(); // Convert the unicode string to an ansi string. - InternalWideToAnsi(stringRef->GetBuffer(), Length, lpstr, allocLength, fBestFitMapping, fThrowOnUnmappableChar); - lpstr[Length] = 0; + int bytesWritten = InternalWideToAnsi(stringRef->GetBuffer(), Length, lpstr, allocLength, fBestFitMapping, fThrowOnUnmappableChar); + _ASSERTE(bytesWritten >= 0 && bytesWritten < allocLength); + lpstr[bytesWritten] = 0; } *pOle++ = lpstr;