[PATCH 1/2] memblock: Detect block ID collisions in pa_memimport_get

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

this adds two checks: for block type and that the shm id matches

using %u in pa_log() would save the (int) casts; maybe both, shm_id and 
memory.id could be logged?

thanks, p.
 
> Signed-off-by: David Henningsson <david.henningsson at canonical.com>
> ---
>  src/pulsecore/memblock.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
> index f8b008f..ca24dec 100644
> --- a/src/pulsecore/memblock.c
> +++ b/src/pulsecore/memblock.c
> @@ -1017,6 +1017,11 @@ 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)))) {
> +        if (b->type != PA_MEMBLOCK_IMPORTED || b->per_type.imported.segment->memory.id != shm_id) {
> +            pa_log("Cannot import memory due to to block ID collision (block %d, shm id %d)!", (int) block_id, (int) shm_id);
> +            b = NULL;
> +            goto finish;
> +        }
>          pa_memblock_ref(b);
>          goto finish;
>      }
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux