summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2018-01-30 13:05:56 -0800
committerJanis Danisevskis <jdanis@google.com>2018-01-30 14:03:02 -0800
commit5a0dfa2345913b143bbeca04e25288a5fa4001f8 (patch)
treec71e406ec044d129b092aa854be8e36b4f66d58d
parentd16d923716a4e54ca4c9003ff4b356705f1e10b7 (diff)
downloadkeymaster-5a0dfa2345913b143bbeca04e25288a5fa4001f8.tar.gz
AuthorizationSet: Clear() should also reset the error_ field
Clear() should reset the error field or it does not recover AuthorizationSets that have encountered an error before. Added test ClearRecoversFromError to authorization_set_test.cpp Test: host test (run make in keymaster director) Bug: 72702959 Change-Id: I1c422135cb7d235157d17785f5df927164d1e166
-rw-r--r--android_keymaster/authorization_set.cpp1
-rw-r--r--tests/authorization_set_test.cpp9
2 files changed, 10 insertions, 0 deletions
diff --git a/android_keymaster/authorization_set.cpp b/android_keymaster/authorization_set.cpp
index c26c7d8..7073b5b 100644
--- a/android_keymaster/authorization_set.cpp
+++ b/android_keymaster/authorization_set.cpp
@@ -501,6 +501,7 @@ void AuthorizationSet::Clear() {
memset_s(indirect_data_, 0, indirect_data_size_);
elems_size_ = 0;
indirect_data_size_ = 0;
+ error_ = OK;
}
void AuthorizationSet::FreeData() {
diff --git a/tests/authorization_set_test.cpp b/tests/authorization_set_test.cpp
index f3f4412..8c908c3 100644
--- a/tests/authorization_set_test.cpp
+++ b/tests/authorization_set_test.cpp
@@ -247,6 +247,15 @@ TEST(Deserialization, InvalidLengthField) {
EXPECT_EQ(AuthorizationSet::MALFORMED_DATA, deserialized.is_valid());
}
+TEST(Clear, ClearRecoversFromError) {
+ uint8_t buf[] = {0, 0, 0};
+ AuthorizationSet deserialized(buf, array_length(buf));
+ ASSERT_EQ(AuthorizationSet::MALFORMED_DATA, deserialized.is_valid());
+
+ deserialized.Clear();
+ ASSERT_EQ(AuthorizationSet::OK, deserialized.is_valid());
+}
+
static uint32_t read_uint32(const uint8_t* buf) {
uint32_t val;
memcpy(&val, buf, sizeof(val));