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

David Henningsson david.henningsson at canonical.com
Mon Dec 8 00:51:02 PST 2014


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

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---

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)!",
+                   block_id, shm_id, b->per_type.imported.segment->memory.id);
+            b = NULL;
+            goto finish;
+        }
         pa_memblock_ref(b);
         goto finish;
     }
-- 
1.9.1



More information about the pulseaudio-discuss mailing list