[ADVAPI32]

- Correctly use RtlCreateUnicodeStringFromAsciiz and check for its return value in various places.
It allocates a buffer and initializes is it as empty even if the passed ASCII buffer is NULL.

svn path=/trunk/; revision=64442
This commit is contained in:
Jérôme Gardou 2014-10-01 17:48:17 +00:00
parent 7478b71bc8
commit bd4da28f08

View file

@ -1039,8 +1039,26 @@ RegCreateKeyExA(
UNICODE_STRING ClassString; UNICODE_STRING ClassString;
DWORD ErrorCode; DWORD ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&ClassString, lpClass); RtlInitEmptyUnicodeString(&ClassString, NULL, 0);
RtlCreateUnicodeStringFromAsciiz(&SubKeyString, (LPSTR)lpSubKey); RtlInitEmptyUnicodeString(&SubKeyString, NULL, 0);
if (lpClass)
{
if (!RtlCreateUnicodeStringFromAsciiz(&ClassString, lpClass))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
if (lpSubKey)
{
if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyString, lpSubKey))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
ErrorCode = RegCreateKeyExW( ErrorCode = RegCreateKeyExW(
hKey, hKey,
@ -1053,6 +1071,7 @@ RegCreateKeyExA(
phkResult, phkResult,
lpdwDisposition); lpdwDisposition);
Exit:
RtlFreeUnicodeString(&SubKeyString); RtlFreeUnicodeString(&SubKeyString);
RtlFreeUnicodeString(&ClassString); RtlFreeUnicodeString(&ClassString);
@ -1222,7 +1241,13 @@ RegDeleteKeyExA(
LONG ErrorCode; LONG ErrorCode;
UNICODE_STRING SubKeyName; UNICODE_STRING SubKeyName;
RtlCreateUnicodeStringFromAsciiz(&SubKeyName, (LPSTR)lpSubKey); if (lpSubKey)
{
if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName, lpSubKey))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&SubKeyName, NULL, 0);
ErrorCode = RegDeleteKeyExW(hKey, SubKeyName.Buffer, samDesired, Reserved); ErrorCode = RegDeleteKeyExW(hKey, SubKeyName.Buffer, samDesired, Reserved);
@ -3048,15 +3073,32 @@ RegLoadKeyA(HKEY hKey,
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
LONG ErrorCode; LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&KeyName, RtlInitEmptyUnicodeString(&KeyName, NULL, 0);
(LPSTR)lpSubKey); RtlInitEmptyUnicodeString(&FileName, NULL, 0);
RtlCreateUnicodeStringFromAsciiz(&FileName,
(LPSTR)lpFile); if (lpSubKey)
{
if (!RtlCreateUnicodeStringFromAsciiz(&KeyName, lpSubKey))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
if (lpFile)
{
if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFile))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
ErrorCode = RegLoadKeyW(hKey, ErrorCode = RegLoadKeyW(hKey,
KeyName.Buffer, KeyName.Buffer,
FileName.Buffer); FileName.Buffer);
Exit:
RtlFreeUnicodeString(&FileName); RtlFreeUnicodeString(&FileName);
RtlFreeUnicodeString(&KeyName); RtlFreeUnicodeString(&KeyName);
@ -3313,8 +3355,13 @@ RegOpenKeyExA(
TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n", TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult); hKey, lpSubKey, ulOptions, samDesired, phkResult);
RtlCreateUnicodeStringFromAsciiz(&SubKeyString, if (lpSubKey)
(LPSTR)lpSubKey); {
if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyString, lpSubKey))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&SubKeyString, NULL, 0);
ErrorCode = RegOpenKeyExW(hKey, SubKeyString.Buffer, ulOptions, samDesired, phkResult); ErrorCode = RegOpenKeyExW(hKey, SubKeyString.Buffer, ulOptions, samDesired, phkResult);
@ -3963,7 +4010,10 @@ RegQueryValueExA(
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
if (name) if (name)
RtlCreateUnicodeStringFromAsciiz(&nameW, name); {
if (!RtlCreateUnicodeStringFromAsciiz(&nameW, name))
return ERROR_NOT_ENOUGH_MEMORY;
}
else else
RtlInitEmptyUnicodeString(&nameW, NULL, 0); RtlInitEmptyUnicodeString(&nameW, NULL, 0);
@ -4205,18 +4255,43 @@ RegReplaceKeyA(HKEY hKey,
UNICODE_STRING OldFile; UNICODE_STRING OldFile;
LONG ErrorCode; LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&SubKey, RtlInitEmptyUnicodeString(&SubKey, NULL, 0);
(PCSZ)lpSubKey); RtlInitEmptyUnicodeString(&OldFile, NULL, 0);
RtlCreateUnicodeStringFromAsciiz(&OldFile, RtlInitEmptyUnicodeString(&NewFile, NULL, 0);
(PCSZ)lpOldFile);
RtlCreateUnicodeStringFromAsciiz(&NewFile, if (lpSubKey)
(PCSZ)lpNewFile); {
if (!RtlCreateUnicodeStringFromAsciiz(&SubKey, lpSubKey))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
if (lpOldFile)
{
if (!RtlCreateUnicodeStringFromAsciiz(&OldFile, lpOldFile))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
if (lpNewFile)
{
if (!RtlCreateUnicodeStringFromAsciiz(&NewFile, lpNewFile))
{
ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
goto Exit;
}
}
ErrorCode = RegReplaceKeyW(hKey, ErrorCode = RegReplaceKeyW(hKey,
SubKey.Buffer, SubKey.Buffer,
NewFile.Buffer, NewFile.Buffer,
OldFile.Buffer); OldFile.Buffer);
Exit:
RtlFreeUnicodeString(&OldFile); RtlFreeUnicodeString(&OldFile);
RtlFreeUnicodeString(&NewFile); RtlFreeUnicodeString(&NewFile);
RtlFreeUnicodeString(&SubKey); RtlFreeUnicodeString(&SubKey);
@ -4373,8 +4448,13 @@ RegRestoreKeyA(HKEY hKey,
UNICODE_STRING FileName; UNICODE_STRING FileName;
LONG ErrorCode; LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&FileName, if (lpFile)
(PCSZ)lpFile); {
if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFile))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&FileName, NULL, 0);
ErrorCode = RegRestoreKeyW(hKey, ErrorCode = RegRestoreKeyW(hKey,
FileName.Buffer, FileName.Buffer,
@ -4474,8 +4554,14 @@ RegSaveKeyA(HKEY hKey,
UNICODE_STRING FileName; UNICODE_STRING FileName;
LONG ErrorCode; LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&FileName, if (lpFile)
(LPSTR)lpFile); {
if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFile))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&FileName, NULL, 0);
ErrorCode = RegSaveKeyW(hKey, ErrorCode = RegSaveKeyW(hKey,
FileName.Buffer, FileName.Buffer,
lpSecurityAttributes); lpSecurityAttributes);
@ -4579,8 +4665,14 @@ RegSaveKeyExA(HKEY hKey,
UNICODE_STRING FileName; UNICODE_STRING FileName;
LONG ErrorCode; LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&FileName, if (lpFile)
(LPSTR)lpFile); {
if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFile))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&FileName, NULL, 0);
ErrorCode = RegSaveKeyExW(hKey, ErrorCode = RegSaveKeyExW(hKey,
FileName.Buffer, FileName.Buffer,
lpSecurityAttributes, lpSecurityAttributes,
@ -4917,8 +5009,13 @@ RegUnLoadKeyA(HKEY hKey,
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
DWORD ErrorCode; DWORD ErrorCode;
RtlCreateUnicodeStringFromAsciiz(&KeyName, if (lpSubKey)
(LPSTR)lpSubKey); {
if (!RtlCreateUnicodeStringFromAsciiz(&KeyName, lpSubKey))
return ERROR_NOT_ENOUGH_MEMORY;
}
else
RtlInitEmptyUnicodeString(&KeyName, NULL, 0);
ErrorCode = RegUnLoadKeyW(hKey, ErrorCode = RegUnLoadKeyW(hKey,
KeyName.Buffer); KeyName.Buffer);