In function find_privkeys(), the list-> array is allocated to be of size
lists->key_ids_size. "current" is the index where the next found key will
be written (starts at 0).
The current exit condition is thus incorrect:
if (current > list->key_ids_size)
break;
This will allow "current" to be equal to list->key_ids_size which will
potentially cause an overflow if more keys are returned by the loop than
was originally found when calculating that size.
This is very unlikely, but incorrect nonetheless.
Fix this by using the more classic construct of testing for the array bound
in the loop exit condition, as suggested by Daiki Ueno.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
current = 0;
while (pkcs11_find_objects
(sinfo->module, sinfo->pks, &ctx, 1, &count) == CKR_OK
- && count == 1) {
+ && count == 1
+ && current < list->key_ids_size) {
a[0].type = CKA_ID;
a[0].value = certid_tmp;
return gnutls_assert_val(ret);
current++;
}
-
- if (current > list->key_ids_size)
- break;
}
pkcs11_find_objects_final(sinfo);