summaryrefslogtreecommitdiff
path: root/extensions
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 /extensions
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 'extensions')
-rw-r--r--extensions/source/activex/SOActiveX.cxx16
-rw-r--r--extensions/source/activex/SOActiveX.h2
-rw-r--r--extensions/source/config/WinUserInfo/WinUserInfoBe.cxx23
3 files changed, 15 insertions, 26 deletions
diff --git a/extensions/source/activex/SOActiveX.cxx b/extensions/source/activex/SOActiveX.cxx
index 2d8dc2a73b91..88b3ad7691ca 100644
--- a/extensions/source/activex/SOActiveX.cxx
+++ b/extensions/source/activex/SOActiveX.cxx
@@ -359,7 +359,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CSOActiveX::Load( LPPROPERTYBAG pPropBag, LPER
// all information from the 'object' tag is in strings
if (aVal[ind].vt == VT_BSTR && !wcscmp(aPropNames[ind].pstrName, L"src"))
{
- mCurFileUrl = wcsdup( aVal[ind].bstrVal );
+ mCurFileUrl.AssignBSTR(aVal[ind].bstrVal);
}
else if( aVal[ind].vt == VT_BSTR
&& !wcscmp(aPropNames[ind].pstrName, L"readonly"))
@@ -384,16 +384,10 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CSOActiveX::Load( LPPROPERTYBAG pPropBag, LPER
return hr;
mbReadyForActivation = FALSE;
- if (BSTR bStrUrl = SysAllocString(mCurFileUrl))
- {
- hr = CBindStatusCallback<CSOActiveX>::Download(
- this, &CSOActiveX::CallbackCreateXInputStream, bStrUrl, m_spClientSite, FALSE);
- SysFreeString(bStrUrl);
- if (hr == MK_S_ASYNCHRONOUS)
- hr = S_OK;
- }
- else
- hr = E_OUTOFMEMORY;
+ hr = CBindStatusCallback<CSOActiveX>::Download(
+ this, &CSOActiveX::CallbackCreateXInputStream, mCurFileUrl, m_spClientSite, FALSE);
+ if (hr == MK_S_ASYNCHRONOUS)
+ hr = S_OK;
if ( !SUCCEEDED( hr ) )
{
diff --git a/extensions/source/activex/SOActiveX.h b/extensions/source/activex/SOActiveX.h
index f3a66e183ed5..37d983ae91d5 100644
--- a/extensions/source/activex/SOActiveX.h
+++ b/extensions/source/activex/SOActiveX.h
@@ -81,7 +81,7 @@ protected:
CComPtr<IDispatch> mpDispFrame;
CComPtr<IDispatch> mpInstanceLocker;
CComPtr<IDispatch> mpDispWin;
- OLECHAR const * mCurFileUrl;
+ CComBSTR mCurFileUrl;
BOOL mbLoad;
BOOL mbViewOnly;
WNDCLASSW mPWinClass;
diff --git a/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx b/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
index 9b721d50b36a..787769b50367 100644
--- a/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
+++ b/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
@@ -25,6 +25,7 @@
#include <Security.h>
#include <systools/win32/comtools.hxx>
+#include <systools/win32/oleauto.hxx>
namespace extensions
{
@@ -93,12 +94,12 @@ public:
sal::systools::COMReference<IADsADSystemInfo> pADsys(CLSID_ADSystemInfo, nullptr,
CLSCTX_INPROC_SERVER);
- smartBSTR sUserDN;
- sal::systools::ThrowIfFailed(pADsys->get_UserName(&sUserDN.ptr), "get_UserName failed");
+ sal::systools::BStr sUserDN;
+ sal::systools::ThrowIfFailed(pADsys->get_UserName(&sUserDN), "get_UserName failed");
// If this user is an AD user, then without an active connection to the domain, all the
// above will succeed, and m_sUserDN will be correctly initialized, but the following
// call to ADsGetObject will fail, and we will attempt reading cached values.
- m_sUserDN = o3tl::toU(sUserDN.ptr);
+ m_sUserDN = sUserDN;
OUString sLdapUserDN = "LDAP://" + m_sUserDN;
sal::systools::COMReference<IADsUser> pUser;
sal::systools::ThrowIfFailed(ADsGetObject(o3tl::toW(sLdapUserDN.getStr()), IID_IADsUser,
@@ -146,29 +147,23 @@ public:
virtual OUString GetMail() override { return m_aMap[mail]; }
private:
- struct smartBSTR
- {
- BSTR ptr = nullptr;
- ~smartBSTR() { SysFreeString(ptr); }
- };
-
typedef HRESULT (__stdcall IADsUser::*getstrfunc)(BSTR*);
static OUString Str(IADsUser* pUser, getstrfunc func)
{
- smartBSTR sBstr;
- if (FAILED((pUser->*func)(&sBstr.ptr)))
+ sal::systools::BStr sBstr;
+ if (FAILED((pUser->*func)(&sBstr)))
return "";
- return OUString(o3tl::toU(sBstr.ptr));
+ return OUString(sBstr);
}
static OUString Str(IADsUser* pUser, const wchar_t* property)
{
- smartBSTR sBstrProp{ SysAllocString(property) };
+ sal::systools::BStr sBstrProp{ o3tl::toU(property) };
struct AutoVariant : public VARIANT
{
AutoVariant() { VariantInit(this); }
~AutoVariant() { VariantClear(this); }
} varArr;
- if (FAILED(pUser->GetEx(sBstrProp.ptr, &varArr)))
+ if (FAILED(pUser->GetEx(sBstrProp, &varArr)))
return "";
SAFEARRAY* sa = V_ARRAY(&varArr);
LONG nStart, nEnd;