From c3fdf6a7c567a7507c3558a27006b6f9559493d6 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 3 Jan 2019 17:17:21 -0600 Subject: [PATCH] gprs: Fix allocation of context id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the convertion to l_uintset, the creation of new contexts fails due to a range error being returned from l_uintset_find_unused(). The error happens because the uinset is created with a min-value of 1, but the start-value passed to l_uintset_find_unused() is initialized as 0. Reported-by: Martin Hundebøll --- src/gprs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gprs.c b/src/gprs.c index 7e9e5161..58a998ca 100644 --- a/src/gprs.c +++ b/src/gprs.c @@ -1898,7 +1898,12 @@ static struct pri_context *add_context(struct ofono_gprs *gprs, unsigned int id; struct pri_context *context; - id = l_uintset_find_unused(gprs->used_pids, gprs->last_context_id); + if (gprs->last_context_id) + id = l_uintset_find_unused(gprs->used_pids, + gprs->last_context_id); + else + id = l_uintset_find_unused_min(gprs->used_pids); + if (id > l_uintset_get_max(gprs->used_pids)) return NULL;