From 7a77b41d6a86e98ed60716ece907602ec530ac9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 27 Feb 2013 20:57:56 -0500 Subject: [PATCH] shm: Make sure to not allocate blocks larger than the shared mem area Fixes https://bugzilla.gnome.org/show_bug.cgi?id=681359 --- sys/shm/shmalloc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sys/shm/shmalloc.c b/sys/shm/shmalloc.c index 67bae732fc..62c2bc751b 100644 --- a/sys/shm/shmalloc.c +++ b/sys/shm/shmalloc.c @@ -102,13 +102,11 @@ shm_alloc_space_alloc_block (ShmAllocSpace * self, unsigned long size) prev_item = item; } - /* Did not find space before an existing block */ - if (self->blocks && !item) { - /* Return NULL if there is no big enough space, otherwise, there is space - * at the end */ - if (self->size - prev_end_offset < size) - return NULL; - } + /* Return NULL if there is no big enough space, otherwise, there is space + * at the end */ + assert (prev_end_offset <= self->size); + if (!item && self->size - prev_end_offset < size) + return NULL; block = spalloc_new (ShmAllocBlock); memset (block, 0, sizeof (ShmAllocBlock));