Index: ntoskrnl/fsrtl/filelock.c =================================================================== --- ntoskrnl/fsrtl/filelock.c (révision 57329) +++ ntoskrnl/fsrtl/filelock.c (copie de travail) @@ -380,12 +380,13 @@ if (!FileLock->LockInformation) { LockInfo = ExAllocatePoolWithTag(NonPagedPool, sizeof(LOCK_INFORMATION), 'FLCK'); - FileLock->LockInformation = LockInfo; - if (!FileLock) { + if (!LockInfo) + { IoStatus->Status = STATUS_NO_MEMORY; return FALSE; } - + FileLock->LockInformation = LockInfo; + LockInfo->BelongsTo = FileLock; InitializeListHead(&LockInfo->SharedLocks); @@ -416,13 +417,12 @@ ToInsert.Exclusive.FileLock.ProcessId = Process->UniqueProcessId; ToInsert.Exclusive.FileLock.Key = Key; ToInsert.Exclusive.FileLock.ExclusiveLock = ExclusiveLock; - - Conflict = RtlInsertElementGenericTable - (FileLock->LockInformation, - &ToInsert, - sizeof(ToInsert), - &InsertedNew); - + + Conflict = RtlInsertElementGenericTable(FileLock->LockInformation, + &ToInsert, + sizeof(ToInsert), + &InsertedNew); + if (Conflict && !InsertedNew) { if (Conflict->Exclusive.FileLock.ExclusiveLock || ExclusiveLock) @@ -475,8 +475,9 @@ for (i = 0; i < RtlNumberGenericTableElements(&LockInfo->RangeTable); i++) { Conflict = RtlGetElementGenericTable(&LockInfo->RangeTable, i); + /* The first argument will be inserted as a shared range */ - if (LockCompare(&LockInfo->RangeTable, Conflict, &ToInsert) == GenericEqual) + if (Conflict && (LockCompare(&LockInfo->RangeTable, Conflict, &ToInsert) == GenericEqual)) { if (Conflict->Exclusive.FileLock.ExclusiveLock) { @@ -520,8 +521,9 @@ Conflict->Exclusive.FileLock.StartingByte.LowPart, Conflict->Exclusive.FileLock.EndingByte.HighPart, Conflict->Exclusive.FileLock.EndingByte.LowPart); - Conflict = FsRtlpRebuildSharedLockRange - (FileLock, LockInfo, &ToInsert); + Conflict = FsRtlpRebuildSharedLockRange(FileLock, + LockInfo, + &ToInsert); if (!Conflict) { IoStatus->Status = STATUS_NO_MEMORY; @@ -918,7 +920,6 @@ PLIST_ENTRY SharedRangeEntry; PLOCK_SHARED_RANGE WatchSharedRange; COMBINED_LOCK_ELEMENT RemadeElement; - PCOMBINED_LOCK_ELEMENT RemadeElementInserted = NULL; Find.Exclusive.FileLock.StartingByte = SharedRange->Start; Find.Exclusive.FileLock.EndingByte = SharedRange->End; SharedEntry = SharedRange->Entry.Flink; @@ -939,30 +940,28 @@ SharedRangeEntry != &InternalInfo->SharedLocks; SharedRangeEntry = SharedRangeEntry->Flink) { - COMBINED_LOCK_ELEMENT Find; + COMBINED_LOCK_ELEMENT LockElement; WatchSharedRange = CONTAINING_RECORD(SharedRangeEntry, LOCK_SHARED_RANGE, Entry); - Find.Exclusive.FileLock.StartingByte = WatchSharedRange->Start; - Find.Exclusive.FileLock.EndingByte = WatchSharedRange->End; - if (LockCompare(&InternalInfo->RangeTable, &RemadeElement, &Find) != GenericEqual) + LockElement.Exclusive.FileLock.StartingByte = WatchSharedRange->Start; + LockElement.Exclusive.FileLock.EndingByte = WatchSharedRange->End; + if (LockCompare(&InternalInfo->RangeTable, &RemadeElement, &LockElement) != GenericEqual) { DPRINT("Skipping range %08x%08x:%08x%08x\n", - Find.Exclusive.FileLock.StartingByte.HighPart, - Find.Exclusive.FileLock.StartingByte.LowPart, - Find.Exclusive.FileLock.EndingByte.HighPart, - Find.Exclusive.FileLock.EndingByte.LowPart); + LockElement.Exclusive.FileLock.StartingByte.HighPart, + LockElement.Exclusive.FileLock.StartingByte.LowPart, + LockElement.Exclusive.FileLock.EndingByte.HighPart, + LockElement.Exclusive.FileLock.EndingByte.LowPart); continue; } DPRINT("Re-creating range %08x%08x:%08x%08x\n", - Find.Exclusive.FileLock.StartingByte.HighPart, - Find.Exclusive.FileLock.StartingByte.LowPart, - Find.Exclusive.FileLock.EndingByte.HighPart, - Find.Exclusive.FileLock.EndingByte.LowPart); + LockElement.Exclusive.FileLock.StartingByte.HighPart, + LockElement.Exclusive.FileLock.StartingByte.LowPart, + LockElement.Exclusive.FileLock.EndingByte.HighPart, + LockElement.Exclusive.FileLock.EndingByte.LowPart); RtlZeroMemory(&RemadeElement, sizeof(RemadeElement)); RemadeElement.Exclusive.FileLock.StartingByte = WatchSharedRange->Start; RemadeElement.Exclusive.FileLock.EndingByte = WatchSharedRange->End; - RemadeElementInserted = - FsRtlpRebuildSharedLockRange - (FileLock, InternalInfo, &RemadeElement); + FsRtlpRebuildSharedLockRange(FileLock, InternalInfo, &RemadeElement); } } else Index: ntoskrnl/fsrtl/notify.c =================================================================== --- ntoskrnl/fsrtl/notify.c (révision 57329) +++ ntoskrnl/fsrtl/notify.c (copie de travail) @@ -586,6 +586,13 @@ /* Allocate new notification */ NotifyChange = ExAllocatePoolWithTag(PagedPool | POOL_RAISE_IF_ALLOCATION_FAILURE, sizeof(NOTIFY_CHANGE), 'FSrN'); + + /* + * Sanity check. If NotifyChange == NULL + * then an exception was already raised. + */ + ASSERT(NotifyChange != NULL); + RtlZeroMemory(NotifyChange, sizeof(NOTIFY_CHANGE)); /* Set basic information */ Index: ntoskrnl/fstub/disksup.c =================================================================== --- ntoskrnl/fstub/disksup.c (révision 57329) +++ ntoskrnl/fstub/disksup.c (copie de travail) @@ -446,40 +446,48 @@ DPRINT("RDiskCount %d\n", RDiskCount); - Buffer1 = (PWSTR)ExAllocatePoolWithTag(PagedPool, - 64 * sizeof(WCHAR), TAG_FILE_SYSTEM); - Buffer2 = (PWSTR)ExAllocatePoolWithTag(PagedPool, - 32 * sizeof(WCHAR), TAG_FILE_SYSTEM); + Buffer1 = ExAllocatePoolWithTag(PagedPool, + 64 * sizeof(WCHAR), + TAG_FILE_SYSTEM); + if (!Buffer1) return; - PartialInformation = (PKEY_VALUE_PARTIAL_INFORMATION)ExAllocatePoolWithTag(PagedPool, - sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(REG_DISK_MOUNT_INFO), TAG_FILE_SYSTEM); + Buffer2 = ExAllocatePoolWithTag(PagedPool, + 32 * sizeof(WCHAR), + TAG_FILE_SYSTEM); + if (!Buffer2) + { + ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM); + return; + } - if (!Buffer1 || !Buffer2 || !PartialInformation) return; + PartialInformation = ExAllocatePoolWithTag(PagedPool, + sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(REG_DISK_MOUNT_INFO), + TAG_FILE_SYSTEM); + if (!PartialInformation) + { + ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM); + ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM); + return; + } DiskMountInfo = (PREG_DISK_MOUNT_INFO) PartialInformation->Data; - /* Open or Create the 'MountedDevices' key */ + /* Create or open the 'MountedDevices' key */ RtlInitUnicodeString(&UnicodeString1, L"\\Registry\\Machine\\SYSTEM\\MountedDevices"); InitializeObjectAttributes(&ObjectAttributes, &UnicodeString1, - OBJ_CASE_INSENSITIVE, + OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL); - Status = ZwOpenKey(&hKey, + Status = ZwCreateKey(&hKey, KEY_ALL_ACCESS, - &ObjectAttributes); + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); if (!NT_SUCCESS(Status)) { - Status = ZwCreateKey(&hKey, - KEY_ALL_ACCESS, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - } - if (!NT_SUCCESS(Status)) - { hKey = NULL; DPRINT("ZwCreateKey failed for %wZ, status=%x\n", &UnicodeString1, Status); } @@ -536,6 +544,7 @@ ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM); ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM); if (hKey) ZwClose(hKey); + return; } RtlZeroMemory(LayoutArray, @@ -951,10 +960,7 @@ ExFreePoolWithTag(PartialInformation, TAG_FILE_SYSTEM); ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM); ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM); - if (hKey) - { - ZwClose(hKey); - } + if (hKey) ZwClose(hKey); } #endif Index: ntoskrnl/fstub/fstubex.c =================================================================== --- ntoskrnl/fstub/fstubex.c (révision 57329) +++ ntoskrnl/fstub/fstubex.c (copie de travail) @@ -985,7 +985,7 @@ if ((Disk->SectorCount - 1ULL) != EfiHeader.AlternateLBA) { /* We'll update it. First, count number of sectors needed to store partitions */ - SectorsForPartitions = (EfiHeader.NumberOfEntries * PARTITION_ENTRY_SIZE) / Disk->SectorSize; + SectorsForPartitions = ((ULONGLONG)EfiHeader.NumberOfEntries * PARTITION_ENTRY_SIZE) / Disk->SectorSize; /* Then set first usable LBA: Legacy MBR + GPT header + Partitions entries */ EfiHeader.FirstUsableLBA = SectorsForPartitions + 2; /* Then set last usable LBA: Last sector - GPT header - Partitions entries */