summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-03-22 21:18:04 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-03-22 22:23:56 +0100
commita2c3ef6d8108355ce5daf6ff72310ac93ae745f0 (patch)
treea635bd3b161185f2cabe316d29e1cf1d0c538f5b /dbaccess
parenta83dc2cebb60ec27a0d2606a9b7c196e581766fd (diff)
Move BSTR wrapper to systools, and fix some wrong BSTR uses
BSTR is documented [1] to be prefixed by a 32-bit integer specifying its length *in bytes* (not characters), so passing wchar_t* as BSTR is wrong, and the length member of rtl_uString can't substitute the proper BSTR length, since rtl_uString::length specifies length in characters. Any code taking BSTR and using SysStringLen to get its length would only get half of the passed OUString data. In dbaccess/source/ui/dlg/adodatalinks.cxx, the abovementioned error was implemented. OTOH, OLEVariant::getByteSequence() in connectivity/source/drivers/ado/Aolevariant.cxx passed BSTR from tagVARIANT to ctor of OLEString, which resulted in the BSTR being freed in both dtors of OLEString and OLEVariant (the latter calls VariantClear, which itself clears string when vtfield is VT_BSTR). [1] https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/bstr Change-Id: Iedbd62b20133644258af3660616add7b63cac258 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131950 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/ui/dlg/adodatalinks.cxx14
1 files changed, 6 insertions, 8 deletions
diff --git a/dbaccess/source/ui/dlg/adodatalinks.cxx b/dbaccess/source/ui/dlg/adodatalinks.cxx
index be60cdb9b089..82af63688cc1 100644
--- a/dbaccess/source/ui/dlg/adodatalinks.cxx
+++ b/dbaccess/source/ui/dlg/adodatalinks.cxx
@@ -27,6 +27,7 @@
#include <comphelper/scopeguard.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
#include <systools/win32/comtools.hxx>
+#include <systools/win32/oleauto.hxx>
#include <initguid.h>
#include <adoid.h>
@@ -57,12 +58,11 @@ OUString PromptNew(sal_IntPtr hWnd)
sal::systools::COMReference<ADOConnection> piTmpConnection(piDispatch,
sal::systools::COM_QUERY_THROW);
- BSTR _result = nullptr;
+ sal::systools::BStr _result;
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result),
"get_ConnectionString failed");
- // FIXME: Don't we need SysFreeString(_result)?
- return OUString(o3tl::toU(_result), SysStringLen(_result));
+ return OUString(_result);
}
catch (const sal::systools::ComError&)
{
@@ -80,9 +80,8 @@ OUString PromptEdit(sal_IntPtr hWnd, OUString const & connstr)
sal::systools::COMReference<ADOConnection> piTmpConnection;
piTmpConnection.CoCreateInstance(CLSID_CADOConnection, nullptr, CLSCTX_INPROC_SERVER);
- // FIXME: BSTR is not just cast from a random string
sal::systools::ThrowIfFailed(
- piTmpConnection->put_ConnectionString(const_cast<BSTR>(o3tl::toW(connstr.getStr()))),
+ piTmpConnection->put_ConnectionString(sal::systools::BStr(connstr)),
"put_ConnectionString failed");
// Instantiate DataLinks object.
@@ -111,12 +110,11 @@ OUString PromptEdit(sal_IntPtr hWnd, OUString const & connstr)
piTmpConnection.set(piDispatch, sal::systools::COM_QUERY_THROW);
}
- BSTR _result = nullptr;
+ sal::systools::BStr _result;
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result),
"get_ConnectionString failed");
- // FIXME: Don't we need SysFreeString(_result)?
- return OUString(o3tl::toU(_result), SysStringLen(_result));
+ return OUString(_result);
}
catch (const sal::systools::ComError&)
{