mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Fix bugs in RegQueryValueExA() and RegQueryValueExW() that caused crashes or returned bogus
information if the caller wants to retrieve the value data length only. This fixes some bugs with regedit. svn path=/trunk/; revision=8940
This commit is contained in:
parent
a75dfe1a82
commit
a7456eb968
1 changed files with 60 additions and 42 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: reg.c,v 1.44 2004/02/25 14:25:10 ekohl Exp $
|
/* $Id: reg.c,v 1.45 2004/04/01 13:53:08 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
|
@ -2191,10 +2191,10 @@ RegQueryValueExW (HKEY hKey,
|
||||||
ErrorCode = RtlNtStatusToDosError (Status);
|
ErrorCode = RtlNtStatusToDosError (Status);
|
||||||
SetLastError (ErrorCode);
|
SetLastError (ErrorCode);
|
||||||
MaxCopy = 0;
|
MaxCopy = 0;
|
||||||
if (NULL != lpcbData)
|
if (lpcbData != NULL)
|
||||||
{
|
{
|
||||||
ResultSize = sizeof(*ValueInfo) + *lpcbData;
|
ResultSize = sizeof(*ValueInfo) + *lpcbData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpType != NULL)
|
if (lpType != NULL)
|
||||||
|
@ -2202,27 +2202,35 @@ RegQueryValueExW (HKEY hKey,
|
||||||
*lpType = ValueInfo->Type;
|
*lpType = ValueInfo->Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status) && lpData != NULL)
|
||||||
RtlMoveMemory (lpData,
|
{
|
||||||
ValueInfo->Data,
|
RtlMoveMemory (lpData,
|
||||||
min(ValueInfo->DataLength,MaxCopy));
|
ValueInfo->Data,
|
||||||
|
min(ValueInfo->DataLength, MaxCopy));
|
||||||
|
}
|
||||||
|
|
||||||
if ((ValueInfo->Type == REG_SZ) ||
|
if ((ValueInfo->Type == REG_SZ) ||
|
||||||
(ValueInfo->Type == REG_MULTI_SZ) ||
|
(ValueInfo->Type == REG_MULTI_SZ) ||
|
||||||
(ValueInfo->Type == REG_EXPAND_SZ))
|
(ValueInfo->Type == REG_EXPAND_SZ))
|
||||||
{
|
{
|
||||||
if (MaxCopy > ValueInfo->DataLength)
|
if (lpData != NULL && MaxCopy > ValueInfo->DataLength)
|
||||||
((PWSTR)lpData)[ValueInfo->DataLength / sizeof(WCHAR)] = 0;
|
{
|
||||||
|
((PWSTR)lpData)[ValueInfo->DataLength / sizeof(WCHAR)] = 0;
|
||||||
if (lpcbData) {
|
}
|
||||||
*lpcbData = (ResultSize - sizeof(*ValueInfo));
|
|
||||||
DPRINT("(string) Returning Size: %d\n", *lpcbData);
|
if (lpcbData != NULL)
|
||||||
}
|
{
|
||||||
|
*lpcbData = (ResultSize - sizeof(*ValueInfo));
|
||||||
|
DPRINT("(string) Returning Size: %lu\n", *lpcbData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (lpcbData) {
|
{
|
||||||
*lpcbData = ResultSize - sizeof(*ValueInfo);
|
if (lpcbData != NULL)
|
||||||
DPRINT("(other) Returning Size: %d\n", *lpcbData);
|
{
|
||||||
|
*lpcbData = ResultSize - sizeof(*ValueInfo);
|
||||||
|
DPRINT("(other) Returning Size: %lu\n", *lpcbData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength);
|
DPRINT("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength);
|
||||||
|
@ -2255,7 +2263,7 @@ RegQueryValueExA (HKEY hKey,
|
||||||
DWORD Length;
|
DWORD Length;
|
||||||
DWORD Type;
|
DWORD Type;
|
||||||
|
|
||||||
if ((lpData) && (!lpcbData))
|
if (lpData != NULL && lpcbData == NULL)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return ERROR_INVALID_PARAMETER;
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
@ -2269,10 +2277,10 @@ RegQueryValueExA (HKEY hKey,
|
||||||
0,
|
0,
|
||||||
ValueData.MaximumLength);
|
ValueData.MaximumLength);
|
||||||
if (!ValueData.Buffer)
|
if (!ValueData.Buffer)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return ERROR_OUTOFMEMORY;
|
return ERROR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2284,42 +2292,52 @@ RegQueryValueExA (HKEY hKey,
|
||||||
RtlCreateUnicodeStringFromAsciiz (&ValueName,
|
RtlCreateUnicodeStringFromAsciiz (&ValueName,
|
||||||
(LPSTR)lpValueName);
|
(LPSTR)lpValueName);
|
||||||
|
|
||||||
/* Convert length from USHORT to DWORD */
|
Length = *lpcbData * sizeof(WCHAR);
|
||||||
Length = ValueData.Length;
|
|
||||||
ErrorCode = RegQueryValueExW (hKey,
|
ErrorCode = RegQueryValueExW (hKey,
|
||||||
ValueName.Buffer,
|
ValueName.Buffer,
|
||||||
lpReserved,
|
lpReserved,
|
||||||
&Type,
|
&Type,
|
||||||
(LPBYTE)ValueData.Buffer,
|
(LPBYTE)ValueData.Buffer,
|
||||||
&Length);
|
&Length);
|
||||||
if (lpType != NULL)
|
DPRINT("ErrorCode %lu\n", ErrorCode);
|
||||||
*lpType = Type;
|
|
||||||
|
|
||||||
if ((ErrorCode == ERROR_SUCCESS) && (ValueData.Buffer != NULL))
|
if (ErrorCode == ERROR_SUCCESS ||
|
||||||
|
ErrorCode == ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
|
if (lpType != NULL)
|
||||||
|
{
|
||||||
|
*lpType = Type;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Type == REG_SZ) || (Type == REG_MULTI_SZ) || (Type == REG_EXPAND_SZ))
|
if ((Type == REG_SZ) || (Type == REG_MULTI_SZ) || (Type == REG_EXPAND_SZ))
|
||||||
{
|
{
|
||||||
RtlInitAnsiString(&AnsiString, NULL);
|
if (ErrorCode == ERROR_SUCCESS && ValueData.Buffer != NULL)
|
||||||
AnsiString.Buffer = lpData;
|
{
|
||||||
AnsiString.MaximumLength = *lpcbData;
|
RtlInitAnsiString(&AnsiString, NULL);
|
||||||
ValueData.Length = Length;
|
AnsiString.Buffer = lpData;
|
||||||
ValueData.MaximumLength = ValueData.Length + sizeof(WCHAR);
|
AnsiString.MaximumLength = *lpcbData;
|
||||||
RtlUnicodeStringToAnsiString(&AnsiString, &ValueData, FALSE);
|
ValueData.Length = Length;
|
||||||
|
ValueData.MaximumLength = ValueData.Length + sizeof(WCHAR);
|
||||||
|
RtlUnicodeStringToAnsiString(&AnsiString, &ValueData, FALSE);
|
||||||
|
}
|
||||||
Length = Length / sizeof(WCHAR);
|
Length = Length / sizeof(WCHAR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Length = min(*lpcbData, Length);
|
Length = min(*lpcbData, Length);
|
||||||
RtlMoveMemory(lpData, ValueData.Buffer, Length);
|
if (ErrorCode == ERROR_SUCCESS && ValueData.Buffer != NULL)
|
||||||
|
{
|
||||||
|
RtlMoveMemory(lpData, ValueData.Buffer, Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpcbData != NULL)
|
||||||
|
{
|
||||||
|
*lpcbData = Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpcbData != NULL)
|
if (ValueData.Buffer != NULL)
|
||||||
{
|
|
||||||
*lpcbData = Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ValueData.Buffer)
|
|
||||||
{
|
{
|
||||||
RtlFreeHeap(ProcessHeap, 0, ValueData.Buffer);
|
RtlFreeHeap(ProcessHeap, 0, ValueData.Buffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue