From 504544e1738d678c98bd2219267fa0558a0f9e08 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 19 Aug 2012 13:48:02 +0000 Subject: [PATCH] * fixed null-termination in StringToWideChar() if the buffer is larger than the string (mantis #22669) git-svn-id: trunk@22124 - --- .gitattributes | 1 + rtl/inc/ustrings.inc | 15 +++++++-------- rtl/java/justrings.inc | 15 ++++++++------- tests/webtbs/tw22669.pp | 24 ++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 tests/webtbs/tw22669.pp diff --git a/.gitattributes b/.gitattributes index 686ab81aa2..d467ac9f8c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12783,6 +12783,7 @@ tests/webtbs/tw22593.pp svneol=native#text/plain tests/webtbs/tw2260.pp svneol=native#text/plain tests/webtbs/tw22613.pp svneol=native#text/plain tests/webtbs/tw2266.pp svneol=native#text/plain +tests/webtbs/tw22669.pp svneol=native#text/plain tests/webtbs/tw2267.pp svneol=native#text/plain tests/webtbs/tw2268.pp svneol=native#text/plain tests/webtbs/tw2269.pp svneol=native#text/plain diff --git a/rtl/inc/ustrings.inc b/rtl/inc/ustrings.inc index c20b4e7498..fd2cc3e721 100644 --- a/rtl/inc/ustrings.inc +++ b/rtl/inc/ustrings.inc @@ -1030,16 +1030,15 @@ function WideCharToString(S : PWideChar) : UnicodeString; {$define FPC_HAS_STRING_LEN_TO_WIDECHAR} function StringToWideChar(const Src : RawByteString;Dest : PWideChar;DestSize : SizeInt) : PWideChar; var - temp:widestring; + temp: widestring; + Len: SizeInt; begin widestringmanager.Ansi2WideMoveProc(PChar(Src),StringCodePage(Src),temp,Length(Src)); - if Length(temp)'test' then + halt(1); + s:='0123456789'; + StringToWideChar(s,@buf[1],10); + s:=widestring(pwidechar(@buf[1])); + if s<>'012345678' then + halt(2); + end. +