ODK: Address review comments
Merge of http://go/wvgerrit/95666 Mostly fixing coding styles and a few vulnerability check. Updating tests according to the fix. Bug: 150614088 Bug: 150881959 Test: Ran cdm and odk unit tests Change-Id: I109a96ee8ded089d59ab49c2f94b6833c932fd1e
This commit is contained in:
@@ -226,24 +226,24 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field) {
|
||||
}
|
||||
switch (field->type) {
|
||||
case ODK_UINT16: {
|
||||
uint16_t u16 = htobe16(*static_cast<uint16_t*>(field->value));
|
||||
const uint16_t u16 = htobe16(*static_cast<uint16_t*>(field->value));
|
||||
memcpy(buf, &u16, sizeof(u16));
|
||||
break;
|
||||
}
|
||||
case ODK_UINT32: {
|
||||
uint32_t u32 = htobe32(*static_cast<uint32_t*>(field->value));
|
||||
const uint32_t u32 = htobe32(*static_cast<uint32_t*>(field->value));
|
||||
memcpy(buf, &u32, sizeof(u32));
|
||||
break;
|
||||
}
|
||||
case ODK_UINT64: {
|
||||
uint64_t u64 = htobe64(*static_cast<uint64_t*>(field->value));
|
||||
const uint64_t u64 = htobe64(*static_cast<uint64_t*>(field->value));
|
||||
memcpy(buf, &u64, sizeof(u64));
|
||||
break;
|
||||
}
|
||||
case ODK_SUBSTRING: {
|
||||
OEMCrypto_Substring* s = static_cast<OEMCrypto_Substring*>(field->value);
|
||||
uint32_t off = htobe32(s->offset);
|
||||
uint32_t len = htobe32(s->length);
|
||||
const uint32_t off = htobe32(s->offset);
|
||||
const uint32_t len = htobe32(s->length);
|
||||
memcpy(buf, &off, sizeof(off));
|
||||
memcpy(buf + sizeof(off), &len, sizeof(len));
|
||||
break;
|
||||
@@ -264,7 +264,7 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field) {
|
||||
|
||||
OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf,
|
||||
const ODK_Field* field) {
|
||||
if (field == nullptr || field->value == nullptr) {
|
||||
if (buf == nullptr || field == nullptr || field->value == nullptr) {
|
||||
return ODK_ERROR_CORE_MESSAGE;
|
||||
}
|
||||
switch (field->type) {
|
||||
@@ -311,7 +311,7 @@ OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf,
|
||||
|
||||
OEMCryptoResult ODK_DumpSingleField(const uint8_t* buf,
|
||||
const ODK_Field* field) {
|
||||
if (field == nullptr || field->value == nullptr) {
|
||||
if (buf == nullptr || field == nullptr || field->value == nullptr) {
|
||||
return ODK_ERROR_CORE_MESSAGE;
|
||||
}
|
||||
switch (field->type) {
|
||||
@@ -442,7 +442,7 @@ void ODK_ResetOdkFields(std::vector<ODK_Field>* fields) {
|
||||
}
|
||||
for (auto& field : *fields) {
|
||||
if (field.value != nullptr) {
|
||||
size_t size = ODK_AllocSize(field.type);
|
||||
const size_t size = ODK_AllocSize(field.type);
|
||||
memset(field.value, 0, size);
|
||||
}
|
||||
}
|
||||
@@ -450,7 +450,7 @@ void ODK_ResetOdkFields(std::vector<ODK_Field>* fields) {
|
||||
|
||||
void ODK_BuildMessageBuffer(ODK_CoreMessage* core_message,
|
||||
const std::vector<ODK_Field>& extra_fields,
|
||||
uint8_t*& buf, uint32_t* buf_size) {
|
||||
uint8_t** buf, uint32_t* buf_size) {
|
||||
ASSERT_TRUE(core_message != nullptr);
|
||||
ASSERT_TRUE(buf_size != nullptr);
|
||||
std::vector<ODK_Field> total_fields = {
|
||||
@@ -477,10 +477,10 @@ void ODK_BuildMessageBuffer(ODK_CoreMessage* core_message,
|
||||
// update message_size
|
||||
*(reinterpret_cast<uint32_t*>(total_fields[1].value)) = *buf_size;
|
||||
|
||||
buf = new uint8_t[*buf_size]();
|
||||
*buf = new uint8_t[*buf_size];
|
||||
size_t bytes_written = 0;
|
||||
// serialize ODK fields to message buffer
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, ODK_IterFields(ODK_WRITE, buf, SIZE_MAX,
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, ODK_IterFields(ODK_WRITE, *buf, SIZE_MAX,
|
||||
&bytes_written, total_fields));
|
||||
EXPECT_EQ(bytes_written, *buf_size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user