diff options
author | Janis Danisevskis <jdanis@google.com> | 2018-11-14 17:44:20 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-11-14 17:44:20 -0800 |
commit | 7b5b901b628536d2a0799b4e0c1f7e879f8d6fa3 (patch) | |
tree | 9e8416bafaf77a044902f5e578fa927ee47b8717 | |
parent | f23927cb6df5277e4d035c8271ed4a9ee0077065 (diff) | |
parent | 91a01c5cfcff48e56cb926064d59821ecf77bd63 (diff) |
Merge "Removed unsafe use of hidl_vec<>.setToExternal"
am: 91a01c5cfc
Change-Id: Iea06598d45b23d6038aeb6ee76ef9d19621a6152
3 files changed, 13 insertions, 21 deletions
diff --git a/keymaster/3.0/vts/functional/authorization_set.h b/keymaster/3.0/vts/functional/authorization_set.h index 5f92d816a1..60b00e4320 100644 --- a/keymaster/3.0/vts/functional/authorization_set.h +++ b/keymaster/3.0/vts/functional/authorization_set.h @@ -201,7 +201,7 @@ class AuthorizationSet { void push_back(TypedTag<TagType::BYTES, tag> ttag, const uint8_t* data, size_t data_length) { hidl_vec<uint8_t> new_blob; new_blob.setToExternal(const_cast<uint8_t*>(data), data_length); - push_back(ttag, std::move(new_blob)); + push_back(ttag, new_blob); } /** @@ -225,8 +225,7 @@ class AuthorizationSet { } hidl_vec<KeyParameter> hidl_data() const { - hidl_vec<KeyParameter> result; - result.setToExternal(const_cast<KeyParameter*>(data()), size()); + hidl_vec<KeyParameter> result(begin(), end()); return result; } @@ -252,7 +251,7 @@ class AuthorizationSetBuilder : public AuthorizationSet { size_t data_length) { hidl_vec<uint8_t> new_blob; new_blob.setToExternal(const_cast<uint8_t*>(data), data_length); - push_back(ttag, std::move(new_blob)); + push_back(ttag, new_blob); return *this; } diff --git a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h index ac96c863ae..a131423f6a 100644 --- a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h +++ b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h @@ -214,9 +214,8 @@ class AuthorizationSet { } } - const hidl_vec<KeyParameter> hidl_data() const { - hidl_vec<KeyParameter> result; - result.setToExternal(const_cast<KeyParameter*>(data()), size()); + hidl_vec<KeyParameter> hidl_data() const { + hidl_vec<KeyParameter> result(begin(), end()); return result; } @@ -242,7 +241,7 @@ class AuthorizationSetBuilder : public AuthorizationSet { size_t data_length) { hidl_vec<uint8_t> new_blob; new_blob.setToExternal(const_cast<uint8_t*>(data), data_length); - push_back(ttag, std::move(new_blob)); + push_back(ttag, new_blob); return *this; } diff --git a/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h b/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h index 90a0f1b29f..5e5ae8d0ed 100644 --- a/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h +++ b/keymaster/4.0/support/include/keymasterV4_0/keymaster_utils.h @@ -33,25 +33,19 @@ bool operator<(const HmacSharingParameters& a, const HmacSharingParameters& b); namespace support { -inline static hidl_vec<uint8_t> blob2hidlVec(const uint8_t* data, const size_t length, - bool inPlace = true) { - hidl_vec<uint8_t> result; - result.setToExternal(const_cast<unsigned char*>(data), length, !inPlace); +inline static hidl_vec<uint8_t> blob2hidlVec(const uint8_t* data, const size_t length) { + hidl_vec<uint8_t> result(data, data + length); return result; } -inline static hidl_vec<uint8_t> blob2hidlVec(const std::string& value, bool inPlace = true) { - hidl_vec<uint8_t> result; - result.setToExternal(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(value.data())), - static_cast<size_t>(value.size()), !inPlace); +inline static hidl_vec<uint8_t> blob2hidlVec(const std::string& value) { + hidl_vec<uint8_t> result(reinterpret_cast<const uint8_t*>(value.data()), + reinterpret_cast<const uint8_t*>(value.data()) + value.size()); return result; } -inline static hidl_vec<uint8_t> blob2hidlVec(const std::vector<uint8_t>& blob, - bool inPlace = true) { - hidl_vec<uint8_t> result; - result.setToExternal(const_cast<uint8_t*>(blob.data()), static_cast<size_t>(blob.size()), - !inPlace); +inline static hidl_vec<uint8_t> blob2hidlVec(const std::vector<uint8_t>& blob) { + hidl_vec<uint8_t> result(blob.data(), blob.data() + static_cast<size_t>(blob.size())); return result; } |