diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index 450d5cdf33..c575ce5a39 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -7930,13 +7930,16 @@ HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid) if (!pStm || !pclsid) return E_INVALIDARG; + /* clear the output args */ + memcpy(pclsid, &CLSID_NULL, sizeof(*pclsid)); + res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte); if (FAILED(res)) return res; if (nbByte != sizeof(CLSID)) - return S_FALSE; + return STG_E_READFAULT; else return S_OK; } diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c index 80b6cb0b76..663bc30c20 100644 --- a/dlls/ole32/tests/storage32.c +++ b/dlls/ole32/tests/storage32.c @@ -31,6 +31,8 @@ DEFINE_GUID( test_stg_cls, 0x88888888, 0x0425, 0x0000, 0,0,0,0,0,0,0,0); +#define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr) + static void test_hglobal_storage_stat(void) { ILockBytes *ilb = NULL; @@ -913,6 +915,36 @@ static void test_transact(void) ok( r == TRUE, "deleted file\n"); } +static void test_ReadClassStm(void) +{ + CLSID clsid; + HRESULT hr; + IStream *pStream; + static const LARGE_INTEGER llZero; + + hr = ReadClassStm(NULL, &clsid); + ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr); + + hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); + ok_ole_success(hr, "CreateStreamOnHGlobal"); + hr = WriteClassStm(pStream, &test_stg_cls); + ok_ole_success(hr, "WriteClassStm"); + + hr = ReadClassStm(pStream, NULL); + ok(hr == E_INVALIDARG, "ReadClassStm should have returned E_INVALIDARG instead of 0x%08x\n", hr); + + /* test not rewound stream */ + hr = ReadClassStm(pStream, &clsid); + ok(hr == STG_E_READFAULT, "ReadClassStm should have returned STG_E_READFAULT instead of 0x%08x\n", hr); + ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid should have been zeroed\n"); + + hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL); + ok_ole_success(hr, "IStream_Seek"); + hr = ReadClassStm(pStream, &clsid); + ok_ole_success(hr, "ReadClassStm"); + ok(IsEqualCLSID(&clsid, &test_stg_cls), "clsid should have been set to CLSID_WineTest\n"); +} + START_TEST(storage32) { test_hglobal_storage_stat(); @@ -923,4 +955,5 @@ START_TEST(storage32) test_storage_refcount(); test_streamenum(); test_transact(); + test_ReadClassStm(); }