gprs: Fix allocation of context id

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 <martin@geanix.com>
This commit is contained in:
Denis Kenzior 2019-01-03 17:17:21 -06:00
parent 7982635328
commit c3fdf6a7c5
1 changed files with 6 additions and 1 deletions

View File

@ -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;