diff options
author | Imre Kis <imre.kis@arm.com> | 2022-07-28 14:48:36 +0200 |
---|---|---|
committer | Imre Kis <imre.kis@arm.com> | 2022-07-29 17:23:08 +0200 |
commit | 40a0c98ee9c08baacc90e36d28332dce35e969eb (patch) | |
tree | d290669f06f5882621689afe7f38c211fdc8afd0 | |
parent | 1b0c520279445fc4d85fc582eda5e5ff5f380c39 (diff) | |
download | trusted-services-40a0c98ee9c08baacc90e36d28332dce35e969eb.tar.gz |
Prevent using empty response in secure_storage_client_get_info
Fix condition which validates response length in
secure_storage_client_get_info.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Iaeb6082023d2876df38691acb97cf6966cdc9c3d
-rw-r--r-- | components/service/secure_storage/backend/secure_storage_client/secure_storage_client.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/components/service/secure_storage/backend/secure_storage_client/secure_storage_client.c b/components/service/secure_storage/backend/secure_storage_client/secure_storage_client.c index cd7c1472e..fed2fe754 100644 --- a/components/service/secure_storage/backend/secure_storage_client/secure_storage_client.c +++ b/components/service/secure_storage/backend/secure_storage_client/secure_storage_client.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -178,11 +178,22 @@ static psa_status_t secure_storage_client_get_info(void *context, /* RPC failure */ psa_status = PSA_ERROR_GENERIC_ERROR; } else { - if (response_length && response_length != sizeof(*response_desc)) { - psa_status = PSA_ERROR_GENERIC_ERROR; - } - else { + if (response_length == sizeof(*response_desc)) { + /* Response length matches the expected size */ psa_status = opstatus; + } else if (!response_length) { + /* + * In case of an empty response use opstatus but + * fall back to PSA_ERROR_GENERIC_ERROR if opstatus + * contains PSA_SUCCESS as this is an invalid case. + */ + if (opstatus != PSA_SUCCESS) + psa_status = opstatus; + else + psa_status = PSA_ERROR_GENERIC_ERROR; + } else { + /* Invalid length */ + psa_status = PSA_ERROR_GENERIC_ERROR; } } |