ntdll: Open application manifest files with FILE_SHARE_DELETE.

Today, RtlCreateActivationContext (CreateActCtxW) opens the source
manifest file via NtOpenFile without the FILE_SHARE_DELETE sharing mode.

This causes CreateActCtxW to fail if the source manifest file was
created with the FILE_DELETE_ON_CLOSE flag.  FILE_DELETE_ON_CLOSE is
often used for temporary files that should be automatically deleted
after use, even if the creator process crashes.

Fix this by specifying FILE_SHARE_DELETE for sharing mode when opening
the source manifest or module file.  This allows the source manifest or
module file to be marked as deleted while it is open.

Note that concurrent deletion is not an issue for the following reasons:

- The ability to read from an open file handle is unaffected by deletion
  of the corresponding file's name.

- RtlCreateActivationContext does not open the source manifest or module
  file by the given filename (lpSource) more than once.
This commit is contained in:
Jinoh Kang 2023-03-18 17:02:22 +09:00 committed by Alexandre Julliard
parent 6cabfcc187
commit bc854efd7c
2 changed files with 2 additions and 2 deletions

View file

@ -2917,7 +2917,6 @@ static void test_CreateActCtx_share_mode(void)
actctx.lpSource = tmp_manifest_pathname;
handle = CreateActCtxW(&actctx);
todo_wine
ok(handle != INVALID_HANDLE_VALUE, "CreateActCtxW returned error %lu\n", GetLastError());
ok(handle != NULL, "CreateActCtxW returned %p\n", handle);

View file

@ -2925,7 +2925,8 @@ static NTSTATUS open_nt_file( HANDLE *handle, UNICODE_STRING *name )
attr.ObjectName = name;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
return NtOpenFile( handle, GENERIC_READ | SYNCHRONIZE, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT );
return NtOpenFile( handle, GENERIC_READ | SYNCHRONIZE, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_SYNCHRONOUS_IO_ALERT );
}
static NTSTATUS get_manifest_in_module( struct actctx_loader* acl, struct assembly_identity* ai,