Skip to content
Snippets Groups Projects
Commit 5b719128 authored by Francisco Casas's avatar Francisco Casas Committed by Alexandre Julliard
Browse files

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.
parent 28d267b7
No related branches found
No related tags found
1 merge request!855vkd3d-shader: Return a valid pointer when count=0 in param allocator (ubsan).
Pipeline #26339 skipped
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment