Module: wine Branch: master Commit: 28debe67d251f91400f4d23e23795a853eda5fee URL: http://source.winehq.org/git/wine.git/?a=commit;h=28debe67d251f91400f4d23e23...
Author: Huw Davies huw@codeweavers.com Date: Wed Mar 1 11:32:05 2017 +0000
oledb32: Fixed length calculation in conversion to DBTYPE_STR.
Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/oledb32/convert.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index ac462f2..e3e29e0 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -813,26 +813,27 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, SysFreeString(b); return hr; } + case DBTYPE_STR: { BSTR b; - DBLENGTH bstr_len; + DBLENGTH length; INT bytes_to_copy; - hr = IDataConvert_DataConvert(iface, src_type, DBTYPE_BSTR, src_len, &bstr_len, + hr = IDataConvert_DataConvert(iface, src_type, DBTYPE_BSTR, src_len, &length, src, &b, sizeof(BSTR), src_status, dst_status, precision, scale, flags); if(hr != S_OK) return hr; - bstr_len = SysStringLen(b); - *dst_len = bstr_len * sizeof(char); /* Doesn't include size for '\0' */ + length = WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b), NULL, 0, NULL, NULL); + *dst_len = length; /* Doesn't include size for '\0' */ *dst_status = DBSTATUS_S_OK; - bytes_to_copy = min(*dst_len + sizeof(char), dst_max_len); + bytes_to_copy = min(length + 1, dst_max_len); if(dst) { if(bytes_to_copy >= sizeof(char)) { - WideCharToMultiByte(CP_ACP, 0, b, bytes_to_copy - sizeof(char), dst, dst_max_len, NULL, NULL); - *((char *)dst + bytes_to_copy / sizeof(char) - 1) = 0; - if(bytes_to_copy < *dst_len + sizeof(char)) + WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b), dst, bytes_to_copy - 1, NULL, NULL); + *((char *)dst + bytes_to_copy - 1) = 0; + if(bytes_to_copy < length + 1) *dst_status = DBSTATUS_S_TRUNCATED; } else