Huw Davies : oledb32: Fix conversion of strings with embedded '\0' to DBTYPE_STR | DBTYPE_BYREF.

Alexandre Julliard julliard at winehq.org
Wed Mar 1 16:45:11 CST 2017


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

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Mar  1 11:32:07 2017 +0000

oledb32: Fix conversion of strings with embedded '\0' to DBTYPE_STR | DBTYPE_BYREF.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/oledb32/convert.c       |  4 ++--
 dlls/oledb32/tests/convert.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c
index e3e29e0..eadac76 100644
--- a/dlls/oledb32/convert.c
+++ b/dlls/oledb32/convert.c
@@ -876,13 +876,13 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
                                       precision, scale, flags);
         if(hr != S_OK) return hr;
 
-        length = WideCharToMultiByte(CP_ACP, 0, b, -1, NULL, 0, NULL, NULL);
+        length = WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b) + 1, NULL, 0, NULL, NULL);
         *dst_len = length - 1; /* Doesn't include size for '\0' */
         *dst_status = DBSTATUS_S_OK;
         *d = CoTaskMemAlloc(length);
 
         if(*d)
-            WideCharToMultiByte(CP_ACP, 0, b, -1, *d, length, NULL, NULL);
+            WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b) + 1, *d, length, NULL, NULL);
         else
             hr = E_OUTOFMEMORY;
         SysFreeString(b);
diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c
index 663f78e..5d0fd17 100644
--- a/dlls/oledb32/tests/convert.c
+++ b/dlls/oledb32/tests/convert.c
@@ -2155,6 +2155,7 @@ static void test_converttobyrefstr(void)
     DBSTATUS dst_status;
     DBLENGTH dst_len;
     static const WCHAR ten[] = {'1','0',0};
+    static const char withnull[] = "test\0ed";
     BSTR b;
     VARIANT v;
 
@@ -2232,6 +2233,37 @@ static void test_converttobyrefstr(void)
     ok(!lstrcmpA("10", dst), "got %s\n", dst);
     CoTaskMemFree(dst);
 
+    memcpy(src, withnull, sizeof(withnull));
+    dst_len = 0x1234;
+    hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, sizeof(withnull), &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
+    ok(dst_len == 8, "got %ld\n", dst_len);
+    ok(!memcmp(withnull, dst, 8), "got %s\n", dst);
+    ok(dst[8] == 0, "got %02x\n", dst[8]);
+    CoTaskMemFree(dst);
+
+    memcpy(src, withnull, sizeof(withnull));
+    dst_len = 0x1234;
+    hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 7, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
+    ok(dst_len == 7, "got %ld\n", dst_len);
+    ok(!memcmp(withnull, dst, 7), "got %s\n", dst);
+    ok(dst[7] == 0, "got %02x\n", dst[7]);
+    CoTaskMemFree(dst);
+
+    memcpy(src, withnull, sizeof(withnull));
+    dst_len = 0x1234;
+    hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 6, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
+    ok(dst_len == 6, "got %ld\n", dst_len);
+    ok(!memcmp(withnull, dst, 6), "got %s\n", dst);
+    ok(dst[6] == 0, "got %02x\n", dst[6]);
+    CoTaskMemFree(dst);
+
+
     dst_len = 44;
     V_VT(&v) = VT_NULL;
     hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, &v, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);




More information about the wine-cvs mailing list