diff options
author | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2019-03-21 15:21:02 +0100 |
---|---|---|
committer | Tomasz Swierczek <t.swierczek@samsung.com> | 2019-05-20 11:07:48 +0200 |
commit | 6a9b2661d5ebf635c46200632873cccfb154dae8 (patch) | |
tree | f6927b4c1d81d7fff8d3a30c3bc8b2a794f8fafb | |
parent | 72e8c2c638e3631f01907cd361f094b39c47bac6 (diff) | |
download | key-manager-6a9b2661d5ebf635c46200632873cccfb154dae8.tar.gz key-manager-6a9b2661d5ebf635c46200632873cccfb154dae8.tar.bz2 key-manager-6a9b2661d5ebf635c46200632873cccfb154dae8.zip |
Be prepared for no data from TA
Deserialization may return an empty buffer with no error. Adjust code to handle
that case.
Change-Id: Ife80b4d35914eda700798e0515812b3b638e735e
-rw-r--r-- | src/manager/crypto/tz-backend/tz-context.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/manager/crypto/tz-backend/tz-context.cpp b/src/manager/crypto/tz-backend/tz-context.cpp index 0b54bb4..eb42ff4 100644 --- a/src/manager/crypto/tz-backend/tz-context.cpp +++ b/src/manager/crypto/tz-backend/tz-context.cpp @@ -553,8 +553,11 @@ void TrustZoneContext::executeCrypt(tz_command cmd, } // data_size should contain how much memory we actually took for our cipher operation - out.resize(outData->data_size); - memcpy(out.data(), outData->data, outData->data_size); + out.clear(); + if (outData) { + out.resize(outData->data_size); + memcpy(out.data(), outData->data, outData->data_size); + } } void TrustZoneContext::executeEncryptAE(const RawBuffer &keyId, @@ -670,10 +673,14 @@ void TrustZoneContext::executeEncryptAE(const RawBuffer &keyId, ThrowErr(Exc::Crypto::InternalError, "Failed to deserialize tag data: ", ret); } - out.resize(outData->data_size); - memcpy(out.data(), outData->data, outData->data_size); + out.clear(); + if (outData) { + out.resize(outData->data_size); + memcpy(out.data(), outData->data, outData->data_size); + } - if (tagData->data_size) { + tag.clear(); + if (tagData && tagData->data_size) { tag.resize(tagData->data_size); memcpy(tag.data(), tagData->data, tagData->data_size); } @@ -790,8 +797,11 @@ void TrustZoneContext::executeDecryptAE(const RawBuffer &keyId, ThrowErr(Exc::Crypto::InternalError, "Failed to deserialize output data: ", ret); } - out.resize(outData->data_size); - memcpy(out.data(), outData->data, outData->data_size); + out.clear(); + if (outData) { + out.resize(outData->data_size); + memcpy(out.data(), outData->data, outData->data_size); + } } void TrustZoneContext::executeSign(tz_algo_type algo, @@ -885,7 +895,7 @@ void TrustZoneContext::executeSign(tz_algo_type algo, KM_OutData* outData = nullptr; ret = KM_ParamsDeserializeOutData(output, &outData); - if (ret) { + if (ret || !outData || outData->data_size == 0) { ThrowErr(Exc::Crypto::InternalError, "Failed to deserialize output data: ", ret); } |