mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 15:48:36 +02:00
anv: Protect memcpy/memset/qsort calls against NULL arguments
Avoids sanitizer errors like: ``` ../src/intel/vulkan/anv_pipeline_cache.c:409:4: runtime error: null pointer passed as argument 1, which is declared to never be null ../src/intel/vulkan/anv_descriptor_set.c:696:4: runtime error: null pointer passed as argument 1, which is declared to never be null ../src/intel/vulkan/anv_descriptor_set.c:2709:10: runtime error: null pointer passed as argument 1, which is declared to never be null ../src/intel/vulkan/anv_descriptor_set.c:2709:10: runtime error: null pointer passed as argument 2, which is declared to never be null ``` Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32098>
This commit is contained in:
parent
6e544214d5
commit
b6d11ba5b4
3 changed files with 32 additions and 21 deletions
|
|
@ -1536,8 +1536,10 @@ intel_perf_init_metrics(struct intel_perf_config *perf_cfg,
|
||||||
load_oa_metrics(perf_cfg, drm_fd, devinfo);
|
load_oa_metrics(perf_cfg, drm_fd, devinfo);
|
||||||
|
|
||||||
/* sort query groups by name */
|
/* sort query groups by name */
|
||||||
|
if (perf_cfg->queries != NULL) {
|
||||||
qsort(perf_cfg->queries, perf_cfg->n_queries,
|
qsort(perf_cfg->queries, perf_cfg->n_queries,
|
||||||
sizeof(perf_cfg->queries[0]), intel_perf_compare_query_names);
|
sizeof(perf_cfg->queries[0]), intel_perf_compare_query_names);
|
||||||
|
}
|
||||||
|
|
||||||
build_unique_counter_list(perf_cfg);
|
build_unique_counter_list(perf_cfg);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -693,7 +693,10 @@ VkResult anv_CreateDescriptorSetLayout(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize all samplers to 0 */
|
/* Initialize all samplers to 0 */
|
||||||
|
assert((samplers == NULL) == (immutable_sampler_count == 0));
|
||||||
|
if (samplers != NULL) {
|
||||||
memset(samplers, 0, immutable_sampler_count * sizeof(*samplers));
|
memset(samplers, 0, immutable_sampler_count * sizeof(*samplers));
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t buffer_view_count = 0;
|
uint32_t buffer_view_count = 0;
|
||||||
uint32_t dynamic_offset_count = 0;
|
uint32_t dynamic_offset_count = 0;
|
||||||
|
|
@ -2699,6 +2702,8 @@ void anv_UpdateDescriptorSets(
|
||||||
* - RENDER_SURFACE_STATE
|
* - RENDER_SURFACE_STATE
|
||||||
* - SAMPLER_STATE
|
* - SAMPLER_STATE
|
||||||
*/
|
*/
|
||||||
|
assert((dst->desc_surface_mem.map == NULL) == (src->desc_surface_mem.map == NULL));
|
||||||
|
if (dst->desc_surface_mem.map) {
|
||||||
memcpy(dst->desc_surface_mem.map +
|
memcpy(dst->desc_surface_mem.map +
|
||||||
dst_layout->descriptor_surface_offset +
|
dst_layout->descriptor_surface_offset +
|
||||||
(copy->dstArrayElement + j) * dst_layout->descriptor_surface_stride,
|
(copy->dstArrayElement + j) * dst_layout->descriptor_surface_stride,
|
||||||
|
|
@ -2706,6 +2711,10 @@ void anv_UpdateDescriptorSets(
|
||||||
src_layout->descriptor_surface_offset +
|
src_layout->descriptor_surface_offset +
|
||||||
(copy->srcArrayElement + j) * src_layout->descriptor_surface_stride,
|
(copy->srcArrayElement + j) * src_layout->descriptor_surface_stride,
|
||||||
copy_surface_element_size);
|
copy_surface_element_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((dst->desc_sampler_mem.map == NULL) == (src->desc_sampler_mem.map == NULL));
|
||||||
|
if (dst->desc_sampler_mem.map) {
|
||||||
memcpy(dst->desc_sampler_mem.map +
|
memcpy(dst->desc_sampler_mem.map +
|
||||||
dst_layout->descriptor_sampler_offset +
|
dst_layout->descriptor_sampler_offset +
|
||||||
(copy->dstArrayElement + j) * dst_layout->descriptor_sampler_stride,
|
(copy->dstArrayElement + j) * dst_layout->descriptor_sampler_stride,
|
||||||
|
|
@ -2713,6 +2722,7 @@ void anv_UpdateDescriptorSets(
|
||||||
src_layout->descriptor_sampler_offset +
|
src_layout->descriptor_sampler_offset +
|
||||||
(copy->srcArrayElement + j) * src_layout->descriptor_sampler_stride,
|
(copy->srcArrayElement + j) * src_layout->descriptor_sampler_stride,
|
||||||
copy_sampler_element_size);
|
copy_sampler_element_size);
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy the CPU side data anv_descriptor */
|
/* Copy the CPU side data anv_descriptor */
|
||||||
*dst_desc = *src_desc;
|
*dst_desc = *src_desc;
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ anv_shader_bin_create(struct anv_device *device,
|
||||||
INTEL_DEBUG(DEBUG_SHADER_PRINT) ?
|
INTEL_DEBUG(DEBUG_SHADER_PRINT) ?
|
||||||
brw_stage_prog_data_printf_string_size(prog_data_in) : 0);
|
brw_stage_prog_data_printf_string_size(prog_data_in) : 0);
|
||||||
|
|
||||||
if (!vk_multialloc_alloc(&ma, &device->vk.alloc,
|
if (!vk_multialloc_zalloc(&ma, &device->vk.alloc,
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
|
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -406,14 +406,13 @@ anv_shader_bin_create(struct anv_device *device,
|
||||||
typed_memcpy(prog_data_relocs, prog_data_in->relocs,
|
typed_memcpy(prog_data_relocs, prog_data_in->relocs,
|
||||||
prog_data_in->num_relocs);
|
prog_data_in->num_relocs);
|
||||||
prog_data->relocs = prog_data_relocs;
|
prog_data->relocs = prog_data_relocs;
|
||||||
memset(prog_data_param, 0,
|
|
||||||
prog_data->nr_params * sizeof(*prog_data_param));
|
|
||||||
prog_data->param = prog_data_param;
|
prog_data->param = prog_data_param;
|
||||||
prog_data->printf_info = printf_infos;
|
prog_data->printf_info = printf_infos;
|
||||||
shader->prog_data = prog_data;
|
shader->prog_data = prog_data;
|
||||||
shader->prog_data_size = prog_data_size;
|
shader->prog_data_size = prog_data_size;
|
||||||
|
|
||||||
assert(num_stats <= ARRAY_SIZE(shader->stats));
|
assert(num_stats <= ARRAY_SIZE(shader->stats));
|
||||||
|
assert((stats != NULL) || (num_stats == 0));
|
||||||
typed_memcpy(shader->stats, stats, num_stats);
|
typed_memcpy(shader->stats, stats, num_stats);
|
||||||
shader->num_stats = num_stats;
|
shader->num_stats = num_stats;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue