[pulseaudio-discuss] [PATCH v2] memblock: Detect block ID collisions in pa_memimport_get

Peter Meerwald pmeerw at pmeerw.net
Mon Dec 8 05:49:34 PST 2014


> Make sure we don't hand out the wrong block, in case we have the
> same block ID in different SHM segments.

typo below, looks good otherwise

thanks, p.

> ---
> 
> I pushed the second patch, which actually fixes the problem.
> 
> Looking at the code, I couldn't find a way b->type could be anything
> else than PA_MEMBLOCK_IMPORTED, so I think the assert is safe.
> 
>  src/pulsecore/memblock.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
> index eb85d1f..047a44a 100644
> --- a/src/pulsecore/memblock.c
> +++ b/src/pulsecore/memblock.c
> @@ -1019,6 +1019,13 @@ pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_i
>      pa_mutex_lock(i->mutex);
>  
>      if ((b = pa_hashmap_get(i->blocks, PA_UINT32_TO_PTR(block_id)))) {
> +        pa_assert(b->type == PA_MEMBLOCK_IMPORTED);
> +        if (b->per_type.imported.segment->memory.id != shm_id) {
> +            pa_log("Cannot import memory due to to block ID collision (block ID %u, expected shm ID %u, found shm ID %u)!",

to to 

> +                   block_id, shm_id, b->per_type.imported.segment->memory.id);
> +            b = NULL;
> +            goto finish;
> +        }
>          pa_memblock_ref(b);
>          goto finish;
>      }
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)


More information about the pulseaudio-discuss mailing list