Vincent Povirk : ole32: Do not allow the same stream to be opened twice.

Alexandre Julliard julliard at winehq.org
Thu Nov 19 10:15:19 CST 2009


Module: wine
Branch: master
Commit: 371f6a4818ee3739282f29a3259f86357e4e47a0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=371f6a4818ee3739282f29a3259f86357e4e47a0

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Wed Nov 18 10:38:10 2009 -0600

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);




More information about the wine-cvs mailing list