Always return success instead of overflow if caller didn't specify a

buffer.
This commit is contained in:
Alexandre Julliard 2001-02-14 21:45:52 +00:00
parent 1da4707f05
commit c661583200
1 changed files with 74 additions and 74 deletions

View File

@ -447,6 +447,7 @@ DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWO
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
if (class) if (class)
{ {
@ -460,32 +461,30 @@ DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWO
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
} }
if (!status) if (status) goto done;
if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
{ {
if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len)) status = STATUS_BUFFER_OVERFLOW;
{ }
status = STATUS_BUFFER_OVERFLOW; else
} {
else memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
{ class[info->ClassLength/sizeof(WCHAR)] = 0;
memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
class[info->ClassLength/sizeof(WCHAR)] = 0;
}
} }
} }
else status = STATUS_SUCCESS;
if (!status || status == STATUS_BUFFER_OVERFLOW) if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
{ if (subkeys) *subkeys = info->SubKeys;
if (class_len) *class_len = info->ClassLength / sizeof(WCHAR); if (max_subkey) *max_subkey = info->MaxNameLen;
if (subkeys) *subkeys = info->SubKeys; if (max_class) *max_class = info->MaxClassLen;
if (max_subkey) *max_subkey = info->MaxNameLen; if (values) *values = info->Values;
if (max_class) *max_class = info->MaxClassLen; if (max_value) *max_value = info->MaxValueNameLen;
if (values) *values = info->Values; if (max_data) *max_data = info->MaxValueDataLen;
if (max_value) *max_value = info->MaxValueNameLen; if (modif) *modif = info->LastWriteTime;
if (max_data) *max_data = info->MaxValueDataLen;
if (modif) *modif = info->LastWriteTime;
}
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -502,7 +501,7 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
NTSTATUS status; NTSTATUS status;
char buffer[256], *buf_ptr = buffer; char buffer[256], *buf_ptr = buffer;
KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer; KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
DWORD total_size; DWORD total_size, len;
TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0, TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
reserved, subkeys, max_subkey, values, max_value, max_data, security, modif ); reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
@ -511,6 +510,7 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
if (class || class_len) if (class || class_len)
{ {
@ -524,39 +524,37 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size ); status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
} }
if (!status) if (status) goto done;
len = WideCharToMultiByte( CP_ACP, 0,
(WCHAR *)(buf_ptr + info->ClassOffset),
info->ClassLength/sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (class_len)
{ {
DWORD len = WideCharToMultiByte( CP_ACP, 0, if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
(WCHAR *)(buf_ptr + info->ClassOffset), *class_len = len;
info->ClassLength/sizeof(WCHAR), }
NULL, 0, NULL, NULL ); if (class && !status)
if (class_len) {
{ WideCharToMultiByte( CP_ACP, 0,
if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW; (WCHAR *)(buf_ptr + info->ClassOffset),
*class_len = len; info->ClassLength/sizeof(WCHAR),
} class, len, NULL, NULL );
if (class && !status) class[len] = 0;
{
WideCharToMultiByte( CP_ACP, 0,
(WCHAR *)(buf_ptr + info->ClassOffset),
info->ClassLength/sizeof(WCHAR),
class, len, NULL, NULL );
class[len] = 0;
}
} }
} }
else status = STATUS_SUCCESS;
if (!status || status == STATUS_BUFFER_OVERFLOW) if (subkeys) *subkeys = info->SubKeys;
{ if (max_subkey) *max_subkey = info->MaxNameLen;
if (subkeys) *subkeys = info->SubKeys; if (max_class) *max_class = info->MaxClassLen;
if (max_subkey) *max_subkey = info->MaxNameLen; if (values) *values = info->Values;
if (max_class) *max_class = info->MaxClassLen; if (max_value) *max_value = info->MaxValueNameLen;
if (values) *values = info->Values; if (max_data) *max_data = info->MaxValueDataLen;
if (max_value) *max_value = info->MaxValueNameLen; if (modif) *modif = info->LastWriteTime;
if (max_data) *max_data = info->MaxValueDataLen;
if (modif) *modif = info->LastWriteTime;
}
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError( status ); return RtlNtStatusToDosError( status );
} }
@ -821,6 +819,7 @@ DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWOR
} }
else if (status != STATUS_BUFFER_OVERFLOW) goto done; else if (status != STATUS_BUFFER_OVERFLOW) goto done;
} }
else status = STATUS_SUCCESS;
if (type) *type = info->Type; if (type) *type = info->Type;
if (count) *count = total_size - info_size; if (count) *count = total_size - info_size;
@ -880,36 +879,35 @@ DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD
buf_ptr, total_size, &total_size ); buf_ptr, total_size, &total_size );
} }
if (!status) if (status) goto done;
if (is_string(info->Type))
{ {
if (is_string(info->Type)) DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
(total_size - info_size) /sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (data && len)
{
if (len > *count) status = STATUS_BUFFER_OVERFLOW;
else
{
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
(total_size - info_size) /sizeof(WCHAR), (total_size - info_size) /sizeof(WCHAR),
data, len, NULL, NULL ); NULL, 0, NULL, NULL );
/* if the type is REG_SZ and data is not 0-terminated if (data && len)
* and there is enough space in the buffer NT appends a \0 */
if (len < *count && data[len-1]) data[len] = 0;
}
}
total_size = len + info_size;
}
else if (data)
{ {
if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW; if (len > *count) status = STATUS_BUFFER_OVERFLOW;
else memcpy( data, buf_ptr + info_size, total_size - info_size ); else
{
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
(total_size - info_size) /sizeof(WCHAR),
data, len, NULL, NULL );
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \0 */
if (len < *count && data[len-1]) data[len] = 0;
}
} }
total_size = len + info_size;
}
else if (data)
{
if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
else memcpy( data, buf_ptr + info_size, total_size - info_size );
} }
else if (status != STATUS_BUFFER_OVERFLOW) goto done;
} }
else status = STATUS_SUCCESS;
if (type) *type = info->Type; if (type) *type = info->Type;
if (count) *count = total_size - info_size; if (count) *count = total_size - info_size;
@ -1056,6 +1054,7 @@ DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_co
} }
} }
} }
else status = STATUS_SUCCESS;
if (type) *type = info->Type; if (type) *type = info->Type;
if (count) *count = info->DataLength; if (count) *count = info->DataLength;
@ -1151,6 +1150,7 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset ); else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
} }
} }
else status = STATUS_SUCCESS;
if (type) *type = info->Type; if (type) *type = info->Type;
if (count) *count = info->DataLength; if (count) *count = info->DataLength;