From b33a7ab211b1bbf40804949cfac39c6b58574c32 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 18 Nov 2009 10:38:10 -0600 Subject: [PATCH 5/6] ole32: Do not allow the same stream to be opened twice. --- dlls/ole32/storage32.c | 24 ++++++++++++++++++++++++ dlls/ole32/tests/storage32.c | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index 4cfc76f..23b47ad 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -110,6 +110,8 @@ static BOOL StorageImpl_WriteDWordToBigBlock( StorageImpl* This, static BOOL StorageImpl_ReadDWordFromBigBlock( StorageImpl* This, ULONG blockIndex, ULONG offset, DWORD* value); +static BOOL StorageBaseImpl_IsStreamOpen(StorageBaseImpl * stg, DirRef streamEntry); + /* OLESTREAM memory structure to use for Get and Put Routines */ /* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */ typedef struct @@ -453,6 +455,13 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream( if ( (streamEntryRef!=DIRENTRY_NULL) && (currentEntry.stgType==STGTY_STREAM) ) { + if (StorageBaseImpl_IsStreamOpen(This, streamEntryRef)) + { + /* A single stream cannot be opened a second time. */ + res = STG_E_ACCESSDENIED; + goto end; + } + newStream = StgStreamImpl_Construct(This, grfMode, streamEntryRef); if (newStream!=0) @@ -1807,6 +1816,21 @@ void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm) list_remove(&(strm->StrmListEntry)); } +static BOOL StorageBaseImpl_IsStreamOpen(StorageBaseImpl * stg, DirRef streamEntry) +{ + StgStreamImpl *strm; + + LIST_FOR_EACH_ENTRY(strm, &stg->strmHead, StgStreamImpl, StrmListEntry) + { + if (strm->dirEntry == streamEntry) + { + return TRUE; + } + } + + return FALSE; +} + static void StorageBaseImpl_DeleteAll(StorageBaseImpl * stg) { struct list *cur, *cur2; diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c index 8fa300f..10767e1 100644 --- a/dlls/ole32/tests/storage32.c +++ b/dlls/ole32/tests/storage32.c @@ -1100,13 +1100,13 @@ static void test_substorage_share(void) if (r == S_OK) { r = IStorage_OpenStream(stg, stmname, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stm2); - todo_wine ok(r==STG_E_ACCESSDENIED, "IStorage->OpenStream should fail %08x\n", r); + ok(r==STG_E_ACCESSDENIED, "IStorage->OpenStream should fail %08x\n", r); if (r == S_OK) IStorage_Release(stm2); r = IStorage_OpenStream(stg, stmname, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm2); - todo_wine ok(r==STG_E_ACCESSDENIED, "IStorage->OpenStream should fail %08x\n", r); + ok(r==STG_E_ACCESSDENIED, "IStorage->OpenStream should fail %08x\n", r); if (r == S_OK) IStorage_Release(stm2); -- 1.6.3.3