mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader: Return a valid pointer when count=0 in param allocator (ubsan).
After compiling and linking with '-fsanitize=undefined' the following error pops up in many tests: vkd3d_shader_main.c:2024:12: runtime error: member access within null pointer of type 'struct vkd3d_shader_param_node' This happens in the scenario where shader_param_allocator_get() gets called with 'count = 0' but no allocation has been made yet, so allocator->current is NULL. In this case the result of the function, given by: params = &allocator->current->param[allocator->index * allocator->stride]; is an invalid non-NULL pointer. Functions like shader_sm4_read_instruction() may call vsir_program_get_src_params() or vsir_program_get_dst_params() with 0 counts for various DCL_ instructions, as well as things like NOP, ELSE, and SYNC. We could avoid calling the functions in question with 0 counts, but it doesn't seem worth the effort. Alternatively, we could just return NULL on 'count == 0', but this is also complicated because NULL is interpreted as a memory allocation failure on the callers. So we force allocation of the next node even if 'count = 0' when allocator->current is NULL.
This commit is contained in:
parent
28d267b7c0
commit
5b7191280b
Notes:
Alexandre Julliard
2024-05-13 22:57:56 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Elizabeth Figura (@zfigura) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/855
@ -2004,7 +2004,7 @@ void *shader_param_allocator_get(struct vkd3d_shader_param_allocator *allocator,
|
||||
{
|
||||
void *params;
|
||||
|
||||
if (count > allocator->count - allocator->index)
|
||||
if (!allocator->current || count > allocator->count - allocator->index)
|
||||
{
|
||||
struct vkd3d_shader_param_node *next;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user