[NTOSKRNL]

Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.

CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close

svn path=/trunk/; revision=57400
This commit is contained in:
Hermès Bélusca-Maïto 2012-09-27 17:16:31 +00:00
parent 31418a2eb5
commit 572d5fcaeb
31 changed files with 264 additions and 217 deletions

View file

@ -103,6 +103,12 @@ RtlpCheckIntegerAtom(PWSTR AtomName,
return TRUE;
}
/*
* AtomName cannot be NULL because this
* case was caught by the previous test.
*/
ASSERT(AtomName != NULL);
if (*AtomName != L'#')
return FALSE;

View file

@ -348,7 +348,7 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page)
PMM_SECTION_SEGMENT Segment = NULL;
LARGE_INTEGER FileOffset;
PMEMORY_AREA MemoryArea;
PMMSUPPORT AddressSpace = MmGetKernelAddressSpace();
PMMSUPPORT AddressSpace = NULL;
BOOLEAN Dirty = FALSE;
PVOID Address = NULL;
PEPROCESS Process = NULL;
@ -385,7 +385,6 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page)
DPRINT("No segment association for %x\n", Page);
}
Dirty = MmIsDirtyPageRmap(Page);
DPRINTC("Trying to unmap all instances of %x\n", Page);
@ -409,7 +408,8 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page)
DPRINTC("Process %x Address %x Page %x\n", Process, Address, Page);
if (RMAP_IS_SEGMENT(Address)) {
if (RMAP_IS_SEGMENT(Address))
{
entry = entry->Next;
continue;
}
@ -440,10 +440,10 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page)
KeBugCheck(MEMORY_MANAGEMENT);
}
MmLockAddressSpace(AddressSpace);
do
{
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, Address);
if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
{
@ -505,15 +505,14 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page)
DPRINT1("bail\n");
goto bail;
}
else Status = STATUS_MM_RESTART_OPERATION;
else
{
Status = STATUS_MM_RESTART_OPERATION;
}
}
MmLockAddressSpace(AddressSpace);
}
while (Status == STATUS_MM_RESTART_OPERATION);
MmUnlockAddressSpace(AddressSpace);
if (ProcRef)
{
ObDereferenceObject(Process);

View file

@ -116,13 +116,24 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive,
Hive->ViewLock = ExAllocatePoolWithTag(NonPagedPool,
sizeof(KGUARDED_MUTEX),
TAG_CM);
if (!Hive->ViewLock) return STATUS_INSUFFICIENT_RESOURCES;
if (!Hive->ViewLock)
{
/* Cleanup allocation and fail */
ExFreePoolWithTag(Hive, TAG_CM);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Allocate the flush lock */
Hive->FlusherLock = ExAllocatePoolWithTag(NonPagedPool,
sizeof(ERESOURCE),
TAG_CM);
if (!Hive->FlusherLock) return STATUS_INSUFFICIENT_RESOURCES;
if (!Hive->FlusherLock)
{
/* Cleanup allocations and fail */
ExFreePoolWithTag(Hive->ViewLock, TAG_CM);
ExFreePoolWithTag(Hive, TAG_CM);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Setup the handles */
Hive->FileHandles[HFILE_TYPE_PRIMARY] = Primary;
@ -189,10 +200,10 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive,
(PUNICODE_STRING)FileName);
if (!NT_SUCCESS(Status))
{
/* Clear allocations and fail */
ExFreePool(Hive->ViewLock);
ExFreePool(Hive->FlusherLock);
ExFreePool(Hive);
/* Cleanup allocations and fail */
ExFreePoolWithTag(Hive->FlusherLock, TAG_CM);
ExFreePoolWithTag(Hive->ViewLock, TAG_CM);
ExFreePoolWithTag(Hive, TAG_CM);
return Status;
}
@ -205,10 +216,10 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive,
/* Verify integrity */
if (CmCheckRegistry((PCMHIVE)Hive, TRUE))
{
/* Free all alocations */
ExFreePool(Hive->ViewLock);
ExFreePool(Hive->FlusherLock);
ExFreePool(Hive);
/* Cleanup allocations and fail */
ExFreePoolWithTag(Hive->FlusherLock, TAG_CM);
ExFreePoolWithTag(Hive->ViewLock, TAG_CM);
ExFreePoolWithTag(Hive, TAG_CM);
return STATUS_REGISTRY_CORRUPT;
}
}
@ -231,10 +242,10 @@ NTSTATUS
NTAPI
CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName,
IN PCWSTR Extension OPTIONAL,
IN PHANDLE Primary,
IN PHANDLE Log,
IN PULONG PrimaryDisposition,
IN PULONG LogDisposition,
OUT PHANDLE Primary,
OUT PHANDLE Log,
OUT PULONG PrimaryDisposition,
OUT PULONG LogDisposition,
IN BOOLEAN CreateAllowed,
IN BOOLEAN MarkAsSystemHive,
IN BOOLEAN NoBuffering,

View file

@ -1074,6 +1074,9 @@ CmpParseKey(IN PVOID ParseObject,
/* Grab the KCB */
Kcb = ((PCM_KEY_BODY)ParseObject)->KeyControlBlock;
/* Sanity check */
ASSERT(Kcb != NULL);
/* Fail if the key was marked as deleted */
if (Kcb->Delete)
return STATUS_KEY_DELETED;
@ -1093,6 +1096,9 @@ CmpParseKey(IN PVOID ParseObject,
/* This is now the parent */
ParentKcb = Kcb;
/* Sanity check */
ASSERT(ParentKcb != NULL);
/* Check if everything was found cached */
if (!TotalRemainingSubkeys) ASSERTMSG("Caching not implemented", FALSE);

View file

@ -1104,7 +1104,7 @@ CmpLoadHiveThread(IN PVOID StartContext)
//ULONG RegStart;
ULONG PrimaryDisposition, SecondaryDisposition, ClusterSize;
PCMHIVE CmHive;
HANDLE PrimaryHandle, LogHandle;
HANDLE PrimaryHandle = NULL, LogHandle = NULL;
NTSTATUS Status = STATUS_SUCCESS;
PVOID ErrorParameters;
PAGED_CODE();

View file

@ -192,7 +192,7 @@ DbgkpQueueMessage(IN PEPROCESS Process,
ObDereferenceObject(Process);
/* Free the debug event */
ExFreePool(DebugEvent);
ExFreePoolWithTag(DebugEvent, 'EgbD');
}
}
@ -418,7 +418,7 @@ DbgkpFreeDebugEvent(IN PDEBUG_EVENT DebugEvent)
/* Dereference process and thread and free the event */
ObDereferenceObject(DebugEvent->Process);
ObDereferenceObject(DebugEvent->Thread);
ExFreePool(DebugEvent);
ExFreePoolWithTag(DebugEvent, 'EgbD');
}
VOID

View file

@ -211,7 +211,7 @@ ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
PLIST_ENTRY ListHead, NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
ULONG NlsTablesEncountered = 0;
SIZE_T NlsTableSizes[3]; /* 3 NLS tables */
SIZE_T NlsTableSizes[3] = {0, 0, 0}; /* 3 NLS tables */
/* Check if this is boot-time phase 0 initialization */
if (!ExpInitializationPhase)
@ -405,12 +405,11 @@ ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
if (!NT_SUCCESS(Status))
{
/* Failed, display error */
p = InitBuffer->DebugBuffer;
_snwprintf(p,
256 * sizeof(WCHAR),
_snwprintf(InitBuffer->DebugBuffer,
sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
L"INIT: Unable to allocate Process Parameters. 0x%lx",
Status);
RtlInitUnicodeString(&DebugString, p);
RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
ZwDisplayString(&DebugString);
/* Bugcheck the system */
@ -434,12 +433,11 @@ ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
if (!NT_SUCCESS(Status))
{
/* Failed, display error */
p = InitBuffer->DebugBuffer;
_snwprintf(p,
256 * sizeof(WCHAR),
_snwprintf(InitBuffer->DebugBuffer,
sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
L"INIT: Unable to allocate Process Environment. 0x%lx",
Status);
RtlInitUnicodeString(&DebugString, p);
RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
ZwDisplayString(&DebugString);
/* Bugcheck the system */
@ -560,12 +558,11 @@ ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
if (!NT_SUCCESS(Status))
{
/* Failed, display error */
p = InitBuffer->DebugBuffer;
_snwprintf(p,
256 * sizeof(WCHAR),
_snwprintf(InitBuffer->DebugBuffer,
sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
L"INIT: Unable to create Session Manager. 0x%lx",
Status);
RtlInitUnicodeString(&DebugString, p);
RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
ZwDisplayString(&DebugString);
/* Bugcheck the system */
@ -577,12 +574,11 @@ ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
if (!NT_SUCCESS(Status))
{
/* Failed, display error */
p = InitBuffer->DebugBuffer;
_snwprintf(p,
256 * sizeof(WCHAR),
_snwprintf(InitBuffer->DebugBuffer,
sizeof(InitBuffer->DebugBuffer)/sizeof(WCHAR),
L"INIT: Unable to resume Session Manager. 0x%lx",
Status);
RtlInitUnicodeString(&DebugString, p);
RtlInitUnicodeString(&DebugString, InitBuffer->DebugBuffer);
ZwDisplayString(&DebugString);
/* Bugcheck the system */

View file

@ -150,7 +150,7 @@ ExGetCurrentProcessorCpuUsage(PULONG CpuUsage)
Prcb = KeGetCurrentPrcb();
ScaledIdle = Prcb->IdleThread->KernelTime * 100;
ScaledIdle = (ULONGLONG)Prcb->IdleThread->KernelTime * 100;
TotalTime = Prcb->KernelTime + Prcb->UserTime;
if (TotalTime != 0)
*CpuUsage = (ULONG)(100 - (ScaledIdle / TotalTime));
@ -785,7 +785,7 @@ QSI_DEF(SystemProcessInformation)
}
}
}
if (!ImageNameLength && Process != PsIdleProcess && Process->ImageFileName)
if (!ImageNameLength && Process != PsIdleProcess)
{
ImageNameLength = (USHORT)strlen(Process->ImageFileName) * sizeof(WCHAR);
}
@ -824,7 +824,7 @@ QSI_DEF(SystemProcessInformation)
/* Release the memory allocated by SeLocateProcessImageName */
ExFreePool(ProcessImageName);
}
else if (Process->ImageFileName)
else
{
RtlInitAnsiString(&ImageName, Process->ImageFileName);
RtlAnsiStringToUnicodeString(&SpiCurrent->ImageName, &ImageName, FALSE);

View file

@ -380,11 +380,12 @@ FsRtlPrivateLock(IN PFILE_LOCK FileLock,
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);
@ -475,8 +476,9 @@ FsRtlPrivateLock(IN PFILE_LOCK FileLock,
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 +522,9 @@ FsRtlPrivateLock(IN PFILE_LOCK FileLock,
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 +921,6 @@ FsRtlFastUnlockSingle(IN PFILE_LOCK FileLock,
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 +941,28 @@ FsRtlFastUnlockSingle(IN PFILE_LOCK FileLock,
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

View file

@ -586,6 +586,13 @@ FsRtlNotifyFilterChangeDirectory(IN PNOTIFY_SYNC NotifySync,
/* Allocate new notification */
NotifyChange = ExAllocatePoolWithTag(PagedPool | POOL_RAISE_IF_ALLOCATION_FAILURE,
sizeof(NOTIFY_CHANGE), 'FSrN');
/*
* If NotifyChange == NULL then an
* exception was already raised.
*/
ASSERT(NotifyChange != NULL);
RtlZeroMemory(NotifyChange, sizeof(NOTIFY_CHANGE));
/* Set basic information */

View file

@ -446,30 +446,39 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
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,
KEY_ALL_ACCESS,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
Status = ZwCreateKey(&hKey,
KEY_ALL_ACCESS,
&ObjectAttributes,
@ -477,7 +486,6 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
NULL,
REG_OPTION_NON_VOLATILE,
NULL);
}
if (!NT_SUCCESS(Status))
{
hKey = NULL;
@ -535,7 +543,8 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
ExFreePoolWithTag(PartialInformation, TAG_FILE_SYSTEM);
ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM);
ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
if (hKey) ZwClose(hKey);
if (hKey) ObCloseHandle(hKey, KernelMode);
return;
}
RtlZeroMemory(LayoutArray,
@ -951,10 +960,7 @@ end_assign_disks:
ExFreePoolWithTag(PartialInformation, TAG_FILE_SYSTEM);
ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM);
ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
if (hKey)
{
ZwClose(hKey);
}
if (hKey) ObCloseHandle(hKey, KernelMode);
}
#endif

View file

@ -985,7 +985,7 @@ FstubReadPartitionTableEFI(IN PDISK_INFORMATION Disk,
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 */

View file

@ -801,10 +801,10 @@ NTAPI
CmpOpenHiveFiles(
IN PCUNICODE_STRING BaseName,
IN PCWSTR Extension OPTIONAL,
IN PHANDLE Primary,
IN PHANDLE Log,
IN PULONG PrimaryDisposition,
IN PULONG LogDisposition,
OUT PHANDLE Primary,
OUT PHANDLE Log,
OUT PULONG PrimaryDisposition,
OUT PULONG LogDisposition,
IN BOOLEAN CreateAllowed,
IN BOOLEAN MarkAsSystemHive,
IN BOOLEAN NoBuffering,

View file

@ -227,12 +227,15 @@ IoShutdownSystem(IN ULONG Phase)
NULL,
&Event,
&StatusBlock);
if (Irp)
{
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
/* Wait on the driver */
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
}
}
/* Remove the flag */
ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;

View file

@ -795,6 +795,11 @@ LdrProcessDriverModule(PLDR_DATA_TABLE_ENTRY LdrEntry,
&MissingApiName,
&MissingDriverName,
&LoadedImports);
/* Free the temporary buffer */
ExFreePoolWithTag(Buffer, TAG_LDR_WSTR);
/* Check the result of the imports resolution */
if (!NT_SUCCESS(Status)) return Status;
/* Return */

View file

@ -42,12 +42,17 @@ IopCreateEvent(IN PUNICODE_STRING EventName,
if (!NT_SUCCESS(Status)) return NULL;
/* Get a handle to it */
ObReferenceObjectByHandle(Handle,
Status = ObReferenceObjectByHandle(Handle,
0,
ExEventObjectType,
KernelMode,
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
{
ZwClose(Handle);
return NULL;
}
/* Dereference the extra count, and return the handle */
ObDereferenceObject(Event);

View file

@ -119,7 +119,7 @@ IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject,
{
NTSTATUS Status;
PKNORMAL_ROUTINE NormalRoutine;
PVOID NormalContext;
PVOID NormalContext = NULL;
KIRQL OldIrql;
PAGED_CODE();
IOTRACE(IO_API_DEBUG, "IRP: %p. DO: %p. FO: %p \n",

View file

@ -701,7 +701,7 @@ IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceNam
UNICODE_STRING LinkTarget, KeyName;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE LinkHandle, RegistryHandle, KeyHandle;
WCHAR LinkTargetBuffer[256], KeyNameBuffer[sizeof(L"SystemPartition") / sizeof(WCHAR)];
WCHAR LinkTargetBuffer[256];
UNICODE_STRING CmRegistryMachineSystemName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM");
ASSERT(NtSystemPartitionDeviceName->MaximumLength >= NtSystemPartitionDeviceName->Length + sizeof(WCHAR));
@ -760,13 +760,9 @@ IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceNam
return;
}
/* We'll store in Setup subkey, and as we love fun, we use only one buffer for three writings... */
wcscpy(KeyNameBuffer, L"Setup");
KeyName.Length = sizeof(L"Setup") - sizeof(UNICODE_NULL);
KeyName.MaximumLength = sizeof(L"Setup");
KeyName.Buffer = KeyNameBuffer;
/* Open or create the Setup subkey where we'll store in */
RtlInitUnicodeString(&KeyName, L"Setup");
/* So, open or create the subkey */
Status = IopCreateRegistryKeyEx(&KeyHandle,
RegistryHandle,
&KeyName,
@ -784,9 +780,7 @@ IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceNam
}
/* Prepare first data writing... */
wcscpy(KeyNameBuffer, L"SystemPartition");
KeyName.Length = sizeof(L"SystemPartition") - sizeof(UNICODE_NULL);
KeyName.MaximumLength = sizeof(L"SystemPartition");
RtlInitUnicodeString(&KeyName, L"SystemPartition");
/* Write SystemPartition value which is the target of the symbolic link */
Status = ZwSetValueKey(KeyHandle,
@ -801,9 +795,7 @@ IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceNam
}
/* Prepare for second data writing... */
wcscpy(KeyName.Buffer, L"OsLoaderPath");
KeyName.Length = sizeof(L"OsLoaderPath") - sizeof(UNICODE_NULL);
KeyName.MaximumLength = sizeof(L"OsLoaderPath");
RtlInitUnicodeString(&KeyName, L"OsLoaderPath");
/* Remove trailing slash if any (one slash only excepted) */
if (OsLoaderPathName->Length > sizeof(WCHAR) &&

View file

@ -224,7 +224,7 @@ IopStartRamdisk(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
// Build the symbolic link name and target
//
_snwprintf(SourceString,
sizeof(SourceString),
sizeof(SourceString)/sizeof(WCHAR),
L"\\Device\\Ramdisk%wZ",
&GuidString);
SymbolicLinkName.Length = 38;

View file

@ -377,12 +377,15 @@ IopShutdownBaseFileSystems(IN PLIST_ENTRY ListHead)
NULL,
&Event,
&StatusBlock);
if (Irp)
{
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
/* Wait on the driver */
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
}
}
/* Reset the event */
KeClearEvent(&Event);

View file

@ -80,7 +80,7 @@ IopNotifyPlugPlayNotification(
if (!NT_SUCCESS(Status))
{
KeReleaseGuardedMutex(&PnpNotifyListLock);
ExFreePool(NotificationStructure);
ExFreePoolWithTag(NotificationStructure, TAG_PNP_NOTIFY);
return;
}
break;
@ -192,6 +192,7 @@ IopNotifyPlugPlayNotification(
CallCurrentEntry = TRUE;
}
}
break;
}
default:
{

View file

@ -864,7 +864,7 @@ KdbpCmdRegs(
else if (Argv[0][0] == 'c') /* cregs */
{
ULONG Cr0, Cr2, Cr3, Cr4;
KDESCRIPTOR Gdtr, Idtr;
KDESCRIPTOR Gdtr = {0, 0, 0}, Idtr = {0, 0, 0};
USHORT Ldtr;
static const PCHAR Cr0Bits[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

View file

@ -1137,7 +1137,7 @@ NTAPI
INIT_FUNCTION
KiI386PentiumLockErrataFixup(VOID)
{
KDESCRIPTOR IdtDescriptor;
KDESCRIPTOR IdtDescriptor = {0, 0, 0};
PKIDTENTRY NewIdt, NewIdt2;
/* Allocate memory for a new IDT */

View file

@ -142,7 +142,7 @@ KeStartProfile(IN PKPROFILE Profile,
KeLowerIrql(OldIrql);
/* Free the pool */
if (FreeBuffer) ExFreePool(SourceBuffer);
if (FreeBuffer) ExFreePoolWithTag(SourceBuffer, 'forP');
/* Return whether we could start the profile */
return StartedProfile;

View file

@ -1429,7 +1429,7 @@ NtQueryObject(IN HANDLE ObjectHandle,
POBJECT_HEADER ObjectHeader = NULL;
POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags;
POBJECT_BASIC_INFORMATION BasicInfo;
ULONG InfoLength;
ULONG InfoLength = 0;
PVOID Object = NULL;
NTSTATUS Status;
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();

View file

@ -595,7 +595,12 @@ NtCreateSymbolicLinkObject(OUT PHANDLE LinkHandle,
ExAllocatePoolWithTag(PagedPool,
CapturedLinkTarget.MaximumLength,
TAG_SYMLINK_TARGET);
if (!SymbolicLink->LinkTarget.Buffer) return STATUS_NO_MEMORY;
if (!SymbolicLink->LinkTarget.Buffer)
{
/* Dereference the symbolic link object and fail */
ObDereferenceObject(SymbolicLink);
return STATUS_NO_MEMORY;
}
/* Copy it */
RtlCopyMemory(SymbolicLink->LinkTarget.Buffer,

View file

@ -427,7 +427,7 @@ ObLogSecurityDescriptor(IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
*OutputSecurityDescriptor = &SdHeader->SecurityDescriptor;
/* Free anything that we may have had to create */
if (NewHeader) ExFreePool(NewHeader);
if (NewHeader) ExFreePoolWithTag(NewHeader, TAG_OB_SD_CACHE);
return STATUS_SUCCESS;
}

View file

@ -217,7 +217,7 @@ ObCheckCreateObjectAccess(IN PVOID Object,
{
POBJECT_HEADER ObjectHeader;
POBJECT_TYPE ObjectType;
PSECURITY_DESCRIPTOR SecurityDescriptor;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
BOOLEAN SdAllocated;
BOOLEAN Result = TRUE;
ACCESS_MASK GrantedAccess = 0;
@ -280,7 +280,7 @@ ObpCheckTraverseAccess(IN PVOID Object,
{
POBJECT_HEADER ObjectHeader;
POBJECT_TYPE ObjectType;
PSECURITY_DESCRIPTOR SecurityDescriptor;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
BOOLEAN SdAllocated;
BOOLEAN Result;
ACCESS_MASK GrantedAccess = 0;
@ -338,7 +338,7 @@ ObpCheckObjectReference(IN PVOID Object,
{
POBJECT_HEADER ObjectHeader;
POBJECT_TYPE ObjectType;
PSECURITY_DESCRIPTOR SecurityDescriptor;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
BOOLEAN SdAllocated;
BOOLEAN Result;
ACCESS_MASK GrantedAccess = 0;

View file

@ -91,6 +91,7 @@ PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE Sys
NULL,
&Event,
&IoStatusBlock);
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MinorFunction = IRP_MN_QUERY_POWER;
@ -132,6 +133,7 @@ PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE Syste
NULL,
&Event,
&IoStatusBlock);
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MinorFunction = IRP_MN_SET_POWER;

View file

@ -1006,7 +1006,7 @@ PspTerminateThreadByPointer(IN PETHREAD Thread,
}
/* We failed, free the APC */
ExFreePool(Apc);
ExFreePoolWithTag(Apc, TAG_TERMINATE_APC);
/* Return Status */
return Status;

View file

@ -221,7 +221,7 @@ PspSetPrimaryToken(IN PEPROCESS Process,
PACCESS_TOKEN NewToken = Token;
NTSTATUS Status, AccessStatus;
BOOLEAN Result, SdAllocated;
PSECURITY_DESCRIPTOR SecurityDescriptor;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
SECURITY_SUBJECT_CONTEXT SubjectContext;
PSTRACE(PS_SECURITY_DEBUG, "Process: %p Token: %p\n", Process, Token);
@ -638,7 +638,7 @@ PsImpersonateClient(IN PETHREAD Thread,
if (OldData)
{
/* Someone beat us to it, free our copy */
ExFreePool(Impersonation);
ExFreePoolWithTag(Impersonation, TAG_PS_IMPERSONATION);
Impersonation = OldData;
}
}