diff --git a/provider/client/WSUtil.cpp b/provider/client/WSUtil.cpp index 2bfa558ec..64d99fa9f 100644 --- a/provider/client/WSUtil.cpp +++ b/provider/client/WSUtil.cpp @@ -2077,7 +2077,14 @@ static HRESULT CopyMAPISourceKeyToSoapSourceKey(const SBinary *lpsMAPISourceKey, { if (lpsMAPISourceKey == nullptr || lpsSoapSourceKey == nullptr) return MAPI_E_INVALID_PARAMETER; - lpsSoapSourceKey->__ptr = soap_new_unsignedByte(nullptr, lpsSoapSourceKey->__size); + if (lpsMAPISourceKey->lpb == nullptr) { + lpsSoapSourceKey->__ptr = nullptr; + lpsSoapSourceKey->__size = 0; + return hrSuccess; + } + lpsSoapSourceKey->__ptr = soap_new_unsignedByte(nullptr, lpsMAPISourceKey->cb); + if (lpsSoapSourceKey->__ptr == nullptr) + throw std::bad_alloc(); lpsSoapSourceKey->__size = lpsMAPISourceKey->cb; memcpy(lpsSoapSourceKey->__ptr, lpsMAPISourceKey->lpb, lpsSoapSourceKey->__size); return hrSuccess;