- Initialize out pointer to NULL before access check in

IStorage_CreateStorage.
- WriteClassStg should return E_INVALIDARG if pstg is NULL instead of
  asserting.
- ReadClassStg should return E_INVALIDARG if pstg is NULL instead of
  crashing and a NULL pclsid should cause it to return the same
  value.
This commit is contained in:
Robert Shearman 2005-09-22 10:34:40 +00:00 committed by Alexandre Julliard
parent 1c5967c48c
commit 6bc4327c92
1 changed files with 23 additions and 9 deletions

View File

@ -1057,24 +1057,30 @@ HRESULT WINAPI StorageImpl_CreateStorage(
if (pwcsName == 0) if (pwcsName == 0)
return STG_E_INVALIDNAME; return STG_E_INVALIDNAME;
/*
* Initialize the out parameter
*/
*ppstg = NULL;
/* /*
* Validate the STGM flags * Validate the STGM flags
*/ */
if ( FAILED( validateSTGM(grfMode) ) || if ( FAILED( validateSTGM(grfMode) ) ||
(grfMode & STGM_DELETEONRELEASE) ) (grfMode & STGM_DELETEONRELEASE) )
{
WARN("bad grfMode: 0x%lx\n", grfMode);
return STG_E_INVALIDFLAG; return STG_E_INVALIDFLAG;
}
/* /*
* Check that we're compatible with the parent's storage mode * Check that we're compatible with the parent's storage mode
*/ */
parent_grfMode = STGM_ACCESS_MODE( This->base.ancestorStorage->base.openFlags ); parent_grfMode = STGM_ACCESS_MODE( This->base.ancestorStorage->base.openFlags );
if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) ) if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
{
WARN("access denied\n");
return STG_E_ACCESSDENIED; return STG_E_ACCESSDENIED;
}
/*
* Initialize the out parameter
*/
*ppstg = 0;
/* /*
* Create a property enumeration and search the properties * Create a property enumeration and search the properties
@ -1095,7 +1101,10 @@ HRESULT WINAPI StorageImpl_CreateStorage(
if (STGM_CREATE_MODE(grfMode) == STGM_CREATE) if (STGM_CREATE_MODE(grfMode) == STGM_CREATE)
IStorage_DestroyElement(iface, pwcsName); IStorage_DestroyElement(iface, pwcsName);
else else
{
WARN("file already exists\n");
return STG_E_FILEALREADYEXISTS; return STG_E_FILEALREADYEXISTS;
}
} }
/* /*
@ -1106,7 +1115,10 @@ HRESULT WINAPI StorageImpl_CreateStorage(
newProperty.sizeOfNameString = (lstrlenW(pwcsName)+1)*sizeof(WCHAR); newProperty.sizeOfNameString = (lstrlenW(pwcsName)+1)*sizeof(WCHAR);
if (newProperty.sizeOfNameString > PROPERTY_NAME_BUFFER_LEN) if (newProperty.sizeOfNameString > PROPERTY_NAME_BUFFER_LEN)
{
FIXME("name too long\n");
return STG_E_INVALIDNAME; return STG_E_INVALIDNAME;
}
strcpyW(newProperty.name, pwcsName); strcpyW(newProperty.name, pwcsName);
@ -6117,7 +6129,8 @@ HRESULT WINAPI WriteClassStg(IStorage* pStg, REFCLSID rclsid)
{ {
HRESULT hRes; HRESULT hRes;
assert(pStg != 0); if(!pStg)
return E_INVALIDARG;
hRes = IStorage_SetClass(pStg, rclsid); hRes = IStorage_SetClass(pStg, rclsid);
@ -6134,10 +6147,11 @@ HRESULT WINAPI ReadClassStg(IStorage *pstg,CLSID *pclsid){
STATSTG pstatstg; STATSTG pstatstg;
HRESULT hRes; HRESULT hRes;
TRACE("()\n"); TRACE("(%p, %p)\n", pstg, pclsid);
if(!pstg || !pclsid)
return E_INVALIDARG;
if(pclsid==NULL)
return E_POINTER;
/* /*
* read a STATSTG structure (contains the clsid) from the storage * read a STATSTG structure (contains the clsid) from the storage
*/ */