check_sharing disregards requested access

James Keane james.keane at gmail.com
Thu Aug 16 19:00:45 CDT 2007


The problem happens when a file is opened with read and write, with
r/w sharing attributes.  Then the file is opened again with just read
and read sharing access.

The second operation fails because check_sharing or's the other fd's
existing access and requires the caller to honor the sharing rights,
even if the caller is not requesting those rights.

for example:

foo.c is opened with GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE.

then someone else wants to open foo.c with just GENERIC_READ, FILE_SHARE_READ.

check_access will now fail because the second caller is not honoring
FILE_SHARE_WRITE. but that shouldn't be neccesary as they are not
planning on writing anyways.


it should fix the installer bug here:
http://bugs.winehq.org/show_bug.cgi?id=5024
-------------- next part --------------
diff --git a/server/fd.c b/server/fd.c
index cf3a306..11bb457 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1478,9 +1478,10 @@ static int check_sharing( struct fd *fd, unsigned int access, unsigned int shari
     if ((access & FILE_UNIX_READ_ACCESS) && !(existing_sharing & FILE_SHARE_READ)) return 0;
     if ((access & FILE_UNIX_WRITE_ACCESS) && !(existing_sharing & FILE_SHARE_WRITE)) return 0;
     if ((access & DELETE) && !(existing_sharing & FILE_SHARE_DELETE)) return 0;
-    if ((existing_access & FILE_UNIX_READ_ACCESS) && !(sharing & FILE_SHARE_READ)) return 0;
-    if ((existing_access & FILE_UNIX_WRITE_ACCESS) && !(sharing & FILE_SHARE_WRITE)) return 0;
-    if ((existing_access & DELETE) && !(sharing & FILE_SHARE_DELETE)) return 0;
+    if ((access & FILE_UNIX_READ_ACCESS) && (existing_access & FILE_UNIX_READ_ACCESS) && !(sharing & FILE_SHARE_READ)) return 0;
+    if ((access & FILE_UNIX_WRITE_ACCESS) && (existing_access & FILE_UNIX_WRITE_ACCESS) && !(sharing & FILE_SHARE_WRITE)) return 0;
+    if ((access & DELETE) && (existing_access & DELETE) && !(sharing & FILE_SHARE_DELETE)) return 0;
     return 1;
 }
 


More information about the wine-patches mailing list