null terminate the converted LPStr at the right index (#17079)
authorJeff Schwartz <jeffschw@microsoft.com>
Wed, 21 Mar 2018 20:07:00 +0000 (13:07 -0700)
committerJan Kotas <jkotas@microsoft.com>
Wed, 21 Mar 2018 20:07:00 +0000 (13:07 -0700)
src/vm/olevariant.cpp

index 95c0b9b..35936bb 100644 (file)
@@ -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;