From 158b7148ef7e23a48a0e7a797b93dc3b24dce1d3 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Thu, 11 Feb 2016 10:37:47 +0100 Subject: [PATCH] mtapi_c: fixed null potential null ptr dereference in id pool --- mtapi_c/src/embb_mtapi_id_pool_t.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mtapi_c/src/embb_mtapi_id_pool_t.c b/mtapi_c/src/embb_mtapi_id_pool_t.c index 0f10d96..986d7a3 100644 --- a/mtapi_c/src/embb_mtapi_id_pool_t.c +++ b/mtapi_c/src/embb_mtapi_id_pool_t.c @@ -36,14 +36,19 @@ void embb_mtapi_id_pool_initialize( mtapi_uint_t capacity) { mtapi_uint_t ii; - that->capacity = capacity; that->id_buffer = (mtapi_uint_t*) embb_mtapi_alloc_allocate(sizeof(mtapi_uint_t)*(capacity + 1)); - that->id_buffer[0] = EMBB_MTAPI_IDPOOL_INVALID_ID; - for (ii = 1; ii <= capacity; ii++) { - that->id_buffer[ii] = ii; + if (NULL != that->id_buffer) { + that->capacity = capacity; + that->id_buffer[0] = EMBB_MTAPI_IDPOOL_INVALID_ID; + for (ii = 1; ii <= capacity; ii++) { + that->id_buffer[ii] = ii; + } + that->ids_available = capacity; + } else { + that->capacity = 0; + that->ids_available = 0; } - that->ids_available = capacity; that->put_id_position = 0; that->get_id_position = 1; embb_spin_init(&that->lock); -- libgit2 0.26.0