summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin van der Gracht <robin@protonic.nl>2020-12-14 14:08:31 +0100
committerJérôme Forissier <jerome@forissier.org>2021-01-07 16:54:28 +0100
commit974adb9fb6c5d4d3608ee6d19b99250d43c7e3f6 (patch)
treecaa48a79fbc1d91c9b55f778f3effca37849398b
parenta3c511dfb29d3e2d7bb20aba7f51e9f353df9d33 (diff)
pkcs11: persistent_token: Don't read token object UUIDs if we have none
Do not call TEE_ReadObjectData() when there is no object data to read because the function panics when reading 0 bytes. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
-rw-r--r--ta/pkcs11/src/persistent_token.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/ta/pkcs11/src/persistent_token.c b/ta/pkcs11/src/persistent_token.c
index aecddea7..b8bd15c4 100644
--- a/ta/pkcs11/src/persistent_token.c
+++ b/ta/pkcs11/src/persistent_token.c
@@ -350,16 +350,19 @@ struct ck_token *init_persistent_db(unsigned int token_id)
if (res || size != sizeof(*db_objs))
TEE_Panic(0);
- size += db_objs->count * sizeof(TEE_UUID);
- ptr = TEE_Realloc(db_objs, size);
- if (!ptr)
- goto error;
+ if (db_objs->count > 0) {
+ size += db_objs->count * sizeof(TEE_UUID);
+ ptr = TEE_Realloc(db_objs, size);
+ if (!ptr)
+ goto error;
- db_objs = ptr;
- size -= sizeof(*db_objs);
- res = TEE_ReadObjectData(db_hdl, db_objs->uuids, size, &size);
- if (res || size != (db_objs->count * sizeof(TEE_UUID)))
- TEE_Panic(0);
+ db_objs = ptr;
+ size -= sizeof(*db_objs);
+ res = TEE_ReadObjectData(db_hdl, db_objs->uuids, size,
+ &size);
+ if (res || size != (db_objs->count * sizeof(TEE_UUID)))
+ TEE_Panic(0);
+ }
for (idx = 0; idx < db_objs->count; idx++) {
/* Create an empty object instance */