fixed some missing NULL checks, reported by M Bealby in bug #1110

svn path=/trunk/; revision=20079
This commit is contained in:
Thomas Bluemel 2005-12-11 20:04:38 +00:00
parent d17306c301
commit 7b4feab0a3
3 changed files with 109 additions and 46 deletions

View file

@ -828,16 +828,17 @@ SearchPathA (
LPSTR *lpFilePart LPSTR *lpFilePart
) )
{ {
UNICODE_STRING PathU; UNICODE_STRING PathU = {0};
UNICODE_STRING FileNameU; UNICODE_STRING FileNameU = {0};
UNICODE_STRING ExtensionU; UNICODE_STRING ExtensionU = {0};
UNICODE_STRING BufferU; UNICODE_STRING BufferU = {0};
ANSI_STRING Path; ANSI_STRING Path;
ANSI_STRING FileName; ANSI_STRING FileName;
ANSI_STRING Extension; ANSI_STRING Extension;
ANSI_STRING Buffer; ANSI_STRING Buffer;
PWCHAR FilePartW; PWCHAR FilePartW;
DWORD RetValue; DWORD RetValue = 0;
NTSTATUS Status = STATUS_SUCCESS;
RtlInitAnsiString (&Path, RtlInitAnsiString (&Path,
(LPSTR)lpPath); (LPSTR)lpPath);
@ -849,36 +850,54 @@ SearchPathA (
/* convert ansi (or oem) strings to unicode */ /* convert ansi (or oem) strings to unicode */
if (bIsFileApiAnsi) if (bIsFileApiAnsi)
{ {
RtlAnsiStringToUnicodeString (&PathU, Status = RtlAnsiStringToUnicodeString (&PathU,
&Path, &Path,
TRUE); TRUE);
RtlAnsiStringToUnicodeString (&FileNameU, if (!NT_SUCCESS(Status))
goto Cleanup;
Status = RtlAnsiStringToUnicodeString (&FileNameU,
&FileName, &FileName,
TRUE); TRUE);
RtlAnsiStringToUnicodeString (&ExtensionU, if (!NT_SUCCESS(Status))
goto Cleanup;
Status = RtlAnsiStringToUnicodeString (&ExtensionU,
&Extension, &Extension,
TRUE); TRUE);
if (!NT_SUCCESS(Status))
goto Cleanup;
} }
else else
{ {
RtlOemStringToUnicodeString (&PathU, Status = RtlOemStringToUnicodeString (&PathU,
&Path, &Path,
TRUE); TRUE);
RtlOemStringToUnicodeString (&FileNameU, if (!NT_SUCCESS(Status))
goto Cleanup;
Status = RtlOemStringToUnicodeString (&FileNameU,
&FileName, &FileName,
TRUE); TRUE);
RtlOemStringToUnicodeString (&ExtensionU, if (!NT_SUCCESS(Status))
goto Cleanup;
Status = RtlOemStringToUnicodeString (&ExtensionU,
&Extension, &Extension,
TRUE); TRUE);
if (!NT_SUCCESS(Status))
goto Cleanup;
} }
BufferU.Length = 0;
BufferU.MaximumLength = nBufferLength * sizeof(WCHAR); BufferU.MaximumLength = nBufferLength * sizeof(WCHAR);
BufferU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (), BufferU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0, 0,
BufferU.MaximumLength); BufferU.MaximumLength);
if (BufferU.Buffer == NULL)
{
Status = STATUS_NO_MEMORY;
goto Cleanup;
}
Buffer.Length = 0;
Buffer.MaximumLength = nBufferLength; Buffer.MaximumLength = nBufferLength;
Buffer.Buffer = lpBuffer; Buffer.Buffer = lpBuffer;
@ -889,16 +908,6 @@ SearchPathA (
BufferU.Buffer, BufferU.Buffer,
&FilePartW); &FilePartW);
RtlFreeHeap (RtlGetProcessHeap (),
0,
PathU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
ExtensionU.Buffer);
if (0 != RetValue) if (0 != RetValue)
{ {
BufferU.Length = wcslen(BufferU.Buffer) * sizeof(WCHAR); BufferU.Length = wcslen(BufferU.Buffer) * sizeof(WCHAR);
@ -913,15 +922,31 @@ SearchPathA (
FALSE); FALSE);
/* nul-terminate ascii string */ /* nul-terminate ascii string */
Buffer.Buffer[BufferU.Length / sizeof(WCHAR)] = '\0'; Buffer.Buffer[BufferU.Length / sizeof(WCHAR)] = '\0';
if (NULL != lpFilePart && BufferU.Length != 0)
{
*lpFilePart = strrchr (lpBuffer, '\\') + 1;
}
} }
Cleanup:
RtlFreeHeap (RtlGetProcessHeap (),
0,
PathU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
FileNameU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (),
0,
ExtensionU.Buffer);
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeHeap (RtlGetProcessHeap (),
0, 0,
BufferU.Buffer); BufferU.Buffer);
if (NULL != lpFilePart) if (!NT_SUCCESS(Status))
{ {
*lpFilePart = strrchr (lpBuffer, '\\') + 1; SetLastErrorByStatus(Status);
return 0;
} }
return RetValue; return RetValue;
@ -1032,9 +1057,14 @@ SearchPathW (
if (lpPath == NULL) if (lpPath == NULL)
{ {
AppPathW = (PWCHAR) RtlAllocateHeap(GetProcessHeap(), AppPathW = (PWCHAR) RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
MAX_PATH * sizeof(WCHAR)); MAX_PATH * sizeof(WCHAR));
if (AppPathW == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
return 0;
}
wcscat (AppPathW, NtCurrentPeb()->ProcessParameters->ImagePathName.Buffer); wcscat (AppPathW, NtCurrentPeb()->ProcessParameters->ImagePathName.Buffer);
@ -1052,11 +1082,12 @@ SearchPathW (
len += 1 + GetWindowsDirectoryW(&Buffer, 0); len += 1 + GetWindowsDirectoryW(&Buffer, 0);
len += 1 + wcslen(AppPathW) * sizeof(WCHAR); len += 1 + wcslen(AppPathW) * sizeof(WCHAR);
EnvironmentBufferW = (PWCHAR) RtlAllocateHeap(GetProcessHeap(), EnvironmentBufferW = (PWCHAR) RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
len * sizeof(WCHAR)); len * sizeof(WCHAR));
if (EnvironmentBufferW == NULL) if (EnvironmentBufferW == NULL)
{ {
RtlFreeHeap(RtlGetProcessHeap(), 0, AppPathW);
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return 0; return 0;
} }

View file

@ -353,6 +353,16 @@ WaitNamedPipeW(LPCWSTR lpNamedPipeName,
return FALSE; return FALSE;
} }
/* Now calculate the total length of the structure and allocate it */
WaitPipeInfoSize = FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[0]) +
NewName.Length;
WaitPipeInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, WaitPipeInfoSize);
if (WaitPipeInfo == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
/* Initialize the object attributes */ /* Initialize the object attributes */
DPRINT("Opening: %wZ\n", &DevicePath); DPRINT("Opening: %wZ\n", &DevicePath);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
@ -374,14 +384,10 @@ WaitNamedPipeW(LPCWSTR lpNamedPipeName,
DPRINT1("Status: %lx\n", Status); DPRINT1("Status: %lx\n", Status);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
RtlFreeUnicodeString(&NamedPipeName); RtlFreeUnicodeString(&NamedPipeName);
RtlFreeHeap(RtlGetProcessHeap(), 0, WaitPipeInfo);
return(FALSE); return(FALSE);
} }
/* Now calculate the total length of the structure and allocate it */
WaitPipeInfoSize = FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[0]) +
NewName.Length;
WaitPipeInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, WaitPipeInfoSize);
/* Check what timeout we got */ /* Check what timeout we got */
if (nTimeOut == NMPWAIT_USE_DEFAULT_WAIT) if (nTimeOut == NMPWAIT_USE_DEFAULT_WAIT)
{ {
@ -1022,6 +1028,11 @@ PeekNamedPipe(HANDLE hNamedPipe,
/* Calculate the buffer space that we'll need and allocate it */ /* Calculate the buffer space that we'll need and allocate it */
BufferSize = nBufferSize + FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]); BufferSize = nBufferSize + FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]);
Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize); Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
if (Buffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
/* Tell the driver to seek */ /* Tell the driver to seek */
Status = NtFsControlFile(hNamedPipe, Status = NtFsControlFile(hNamedPipe,

View file

@ -444,7 +444,7 @@ GetVolumeInformationA(
) )
{ {
UNICODE_STRING FileSystemNameU; UNICODE_STRING FileSystemNameU;
UNICODE_STRING VolumeNameU; UNICODE_STRING VolumeNameU = {0};
ANSI_STRING VolumeName; ANSI_STRING VolumeName;
ANSI_STRING FileSystemName; ANSI_STRING FileSystemName;
PWCHAR RootPathNameW; PWCHAR RootPathNameW;
@ -455,11 +455,14 @@ GetVolumeInformationA(
if (lpVolumeNameBuffer) if (lpVolumeNameBuffer)
{ {
VolumeNameU.Length = 0;
VolumeNameU.MaximumLength = nVolumeNameSize * sizeof(WCHAR); VolumeNameU.MaximumLength = nVolumeNameSize * sizeof(WCHAR);
VolumeNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (), VolumeNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0, 0,
VolumeNameU.MaximumLength); VolumeNameU.MaximumLength);
if (VolumeNameU.Buffer == NULL)
{
goto FailNoMem;
}
} }
if (lpFileSystemNameBuffer) if (lpFileSystemNameBuffer)
@ -469,6 +472,19 @@ GetVolumeInformationA(
FileSystemNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (), FileSystemNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0, 0,
FileSystemNameU.MaximumLength); FileSystemNameU.MaximumLength);
if (FileSystemNameU.Buffer == NULL)
{
if (VolumeNameU.Buffer != NULL)
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
VolumeNameU.Buffer);
}
FailNoMem:
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
} }
Result = GetVolumeInformationW (RootPathNameW, Result = GetVolumeInformationW (RootPathNameW,
@ -724,6 +740,11 @@ SetVolumeLabelW(
0, 0,
sizeof(FILE_FS_LABEL_INFORMATION) + sizeof(FILE_FS_LABEL_INFORMATION) +
LabelLength); LabelLength);
if (LabelInfo == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
LabelInfo->VolumeLabelLength = LabelLength; LabelInfo->VolumeLabelLength = LabelLength;
memcpy(LabelInfo->VolumeLabel, memcpy(LabelInfo->VolumeLabel,
lpVolumeName, lpVolumeName,