Commit ca7a7abe authored by Alexandre Julliard's avatar Alexandre Julliard

kernelbase: Add a helper function to validate process/thread attributes.

parent 4356fe0d
......@@ -1696,85 +1696,60 @@ BOOL WINAPI DECLSPEC_HOTPATCH InitializeProcThreadAttributeList( struct _PROC_TH
}
/***********************************************************************
* UpdateProcThreadAttribute (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH UpdateProcThreadAttribute( struct _PROC_THREAD_ATTRIBUTE_LIST *list,
DWORD flags, DWORD_PTR attr, void *value,
SIZE_T size, void *prev_ret, SIZE_T *size_ret )
static inline DWORD validate_proc_thread_attribute( DWORD_PTR attr, SIZE_T size )
{
DWORD mask;
struct proc_thread_attr *entry;
TRACE( "(%p %lx %08Ix %p %Id %p %p)\n", list, flags, attr, value, size, prev_ret, size_ret );
if (list->count >= list->size)
{
SetLastError( ERROR_GEN_FAILURE );
return FALSE;
}
switch (attr)
{
case PROC_THREAD_ATTRIBUTE_PARENT_PROCESS:
if (size != sizeof(HANDLE))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if (size != sizeof(HANDLE)) return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_HANDLE_LIST:
if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size)
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size) return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR:
if (size != sizeof(PROCESSOR_NUMBER))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if (size != sizeof(PROCESSOR_NUMBER)) return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_CHILD_PROCESS_POLICY:
if (size != sizeof(DWORD) && size != sizeof(DWORD64))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if (size != sizeof(DWORD) && size != sizeof(DWORD64)) return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY:
if (size != sizeof(DWORD) && size != sizeof(DWORD64) && size != sizeof(DWORD64) * 2)
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE:
if (size != sizeof(HPCON))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if (size != sizeof(HPCON)) return ERROR_BAD_LENGTH;
break;
case PROC_THREAD_ATTRIBUTE_JOB_LIST:
if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size)
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size) return ERROR_BAD_LENGTH;
break;
default:
SetLastError( ERROR_NOT_SUPPORTED );
FIXME( "Unhandled attribute %Iu\n", attr & PROC_THREAD_ATTRIBUTE_NUMBER );
return ERROR_NOT_SUPPORTED;
}
return 0;
}
/***********************************************************************
* UpdateProcThreadAttribute (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH UpdateProcThreadAttribute( struct _PROC_THREAD_ATTRIBUTE_LIST *list,
DWORD flags, DWORD_PTR attr, void *value,
SIZE_T size, void *prev_ret, SIZE_T *size_ret )
{
DWORD mask, err;
struct proc_thread_attr *entry;
TRACE( "(%p %lx %08Ix %p %Id %p %p)\n", list, flags, attr, value, size, prev_ret, size_ret );
if (list->count >= list->size)
{
SetLastError( ERROR_GEN_FAILURE );
return FALSE;
}
if ((err = validate_proc_thread_attribute( attr, size )))
{
SetLastError( err );
return FALSE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment