Jacek Caban : msvcrt: Use memmove to copy memory in wmemcpy_s.

Alexandre Julliard julliard at winehq.org
Fri Oct 5 16:40:40 CDT 2018


Module: wine
Branch: master
Commit: be56a83fd00cdaf9583a973b1e041f47c5277768
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=be56a83fd00cdaf9583a973b1e041f47c5277768

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Oct  5 16:38:48 2018 +0200

msvcrt: Use memmove to copy memory in wmemcpy_s.

Fixes memory corruption in Outlook 2016.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcr100/tests/msvcr100.c | 14 +++++++++++++-
 dlls/msvcrt/heap.c             |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcr100/tests/msvcr100.c b/dlls/msvcr100/tests/msvcr100.c
index db5a4cb..594ac28 100644
--- a/dlls/msvcr100/tests/msvcr100.c
+++ b/dlls/msvcr100/tests/msvcr100.c
@@ -371,7 +371,7 @@ static BOOL init(void)
 
 static void test_wmemcpy_s(void)
 {
-    static wchar_t dest[8];
+    static wchar_t dest[8], buf[32];
     static const wchar_t tiny[] = {'T',0,'I','N','Y',0};
     static const wchar_t big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
     const wchar_t XX = 0x5858;     /* two 'X' bytes */
@@ -434,6 +434,18 @@ static void test_wmemcpy_s(void)
     okwchars(dest, XX, XX, XX, XX, XX, XX, XX, XX);
     CHECK_CALLED(invalid_parameter_handler);
 
+    ret = p_wmemcpy_s(buf, ARRAY_SIZE(buf), big, ARRAY_SIZE(big));
+    ok(!ret, "wmemcpy_s returned %d\n", ret);
+    ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
+
+    ret = p_wmemcpy_s(buf + 1, ARRAY_SIZE(buf) - 1, buf, ARRAY_SIZE(big));
+    ok(!ret, "wmemcpy_s returned %d\n", ret);
+    ok(!memcmp(buf + 1, big, sizeof(big)), "unexpected buf\n");
+
+    ret = p_wmemcpy_s(buf, ARRAY_SIZE(buf), buf + 1, ARRAY_SIZE(big));
+    ok(!ret, "wmemcpy_s returned %d\n", ret);
+    ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
+
     ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
             "Cannot reset invalid parameter handler\n");
 }
diff --git a/dlls/msvcrt/heap.c b/dlls/msvcrt/heap.c
index b4f11d8..a780896 100644
--- a/dlls/msvcrt/heap.c
+++ b/dlls/msvcrt/heap.c
@@ -826,7 +826,7 @@ int CDECL wmemcpy_s(MSVCRT_wchar_t *dest, MSVCRT_size_t numberOfElements,
         return MSVCRT_ERANGE;
     }
 
-    memcpy(dest, src, sizeof(MSVCRT_wchar_t)*count);
+    memmove(dest, src, sizeof(MSVCRT_wchar_t)*count);
     return 0;
 }
 #endif




More information about the wine-cvs mailing list