Change build info short-length to be based on real length.
[ Cherry-pick of v19 http://go/wvgerrit/219592 ] [ Merge of http://go/wvgerrit/219554 ] The original CheckBuildInformation_OutputLengthAPI17 test was written with the assumption that the estimated length would not be too much larger than the real length of the build info; however this is not true for some vendors. This CL changes the short-buffer length to be based on a real build info length from a successful call to OEMCrypto. Bug: 411308060 Change-Id: I6504288ca59d7d41facaadc45adc76a5236826d9
This commit is contained in:
@@ -399,45 +399,58 @@ TEST_F(OEMCryptoClientTest, CheckBuildInformation_OutputLengthAPI17) {
|
|||||||
ASSERT_GT(build_info_length, kZero)
|
ASSERT_GT(build_info_length, kZero)
|
||||||
<< "Signaling ERROR_SHORT_BUFFER should have assigned a length";
|
<< "Signaling ERROR_SHORT_BUFFER should have assigned a length";
|
||||||
|
|
||||||
|
// Try again using the size they provided, ensuring that it
|
||||||
|
// is successful.
|
||||||
|
const size_t initial_estimate_length = build_info_length;
|
||||||
|
build_info.assign(build_info_length, kNullChar);
|
||||||
|
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||||
|
ASSERT_EQ(result, OEMCrypto_SUCCESS)
|
||||||
|
<< "initial_estimate_length = " << initial_estimate_length
|
||||||
|
<< ", build_info_length (output) = " << build_info_length;
|
||||||
|
ASSERT_GT(build_info_length, kZero) << "Build info cannot be empty";
|
||||||
|
// Ensure the real length is within the size originally specified.
|
||||||
|
// OK if final length is smaller than estimated length.
|
||||||
|
ASSERT_LE(build_info_length, initial_estimate_length);
|
||||||
|
const size_t expected_length = build_info_length;
|
||||||
|
|
||||||
// Force a ERROR_SHORT_BUFFER using a non-zero value.
|
// Force a ERROR_SHORT_BUFFER using a non-zero value.
|
||||||
// Note: It is assumed that vendors will provide more than a single
|
// Note: It is assumed that vendors will provide more than a single
|
||||||
// character of info.
|
// character of info.
|
||||||
const size_t second_attempt_length =
|
const size_t short_length = (expected_length >= 2) ? expected_length / 2 : 1;
|
||||||
(build_info_length >= 2) ? build_info_length / 2 : 1;
|
build_info.assign(short_length, kNullChar);
|
||||||
build_info.assign(second_attempt_length, kNullChar);
|
|
||||||
build_info_length = build_info.size();
|
build_info_length = build_info.size();
|
||||||
|
|
||||||
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||||
ASSERT_EQ(result, OEMCrypto_ERROR_SHORT_BUFFER)
|
ASSERT_EQ(result, OEMCrypto_ERROR_SHORT_BUFFER)
|
||||||
<< "second_attempt_length = " << second_attempt_length
|
<< "short_length = " << short_length
|
||||||
<< ", build_info_length" << build_info_length;
|
<< ", expected_length = " << expected_length << ", build_info_length"
|
||||||
|
<< build_info_length;
|
||||||
// OEM specified build info length should be larger than the
|
// OEM specified build info length should be larger than the
|
||||||
// original length if returning ERROR_SHORT_BUFFER.
|
// original length if returning ERROR_SHORT_BUFFER.
|
||||||
ASSERT_GT(build_info_length, second_attempt_length);
|
ASSERT_GT(build_info_length, short_length);
|
||||||
|
|
||||||
// Final attempt with a buffer large enough buffer, padding to
|
// Final attempt with a buffer large enough buffer, padding to
|
||||||
// ensure the caller truncates.
|
// ensure the caller truncates.
|
||||||
constexpr size_t kBufferPadSize = 42;
|
constexpr size_t kBufferPadSize = 42;
|
||||||
const size_t expected_length = build_info_length;
|
const size_t oversize_length = expected_length + kBufferPadSize;
|
||||||
const size_t final_attempt_length = expected_length + kBufferPadSize;
|
build_info.assign(oversize_length, kNullChar);
|
||||||
build_info.assign(final_attempt_length, kNullChar);
|
|
||||||
build_info_length = build_info.size();
|
build_info_length = build_info.size();
|
||||||
|
|
||||||
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||||
|
|
||||||
ASSERT_EQ(result, OEMCrypto_SUCCESS)
|
ASSERT_EQ(result, OEMCrypto_SUCCESS)
|
||||||
<< "final_attempt_length = " << final_attempt_length
|
<< "oversize_length = " << oversize_length
|
||||||
<< ", expected_length = " << expected_length
|
<< ", expected_length = " << expected_length
|
||||||
<< ", build_info_length = " << build_info_length;
|
<< ", build_info_length (output) = " << build_info_length;
|
||||||
// Ensure not empty.
|
// Ensure not empty.
|
||||||
ASSERT_GT(build_info_length, kZero) << "Build info cannot be empty";
|
ASSERT_GT(build_info_length, kZero) << "Build info cannot be empty";
|
||||||
// Ensure it was truncated down from the padded length.
|
// Ensure it was truncated down from the padded length.
|
||||||
ASSERT_LT(build_info_length, final_attempt_length)
|
ASSERT_LT(build_info_length, oversize_length)
|
||||||
<< "Should have truncated from oversized buffer: expected_length = "
|
<< "Should have truncated from oversized buffer: expected_length = "
|
||||||
<< expected_length;
|
<< expected_length;
|
||||||
// Ensure the real length is within the size originally specified.
|
// Ensure that length is equal to the length of the previous
|
||||||
// OK if final length is smaller than estimated length.
|
// successful call.
|
||||||
ASSERT_LE(build_info_length, expected_length);
|
ASSERT_EQ(build_info_length, expected_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifies that OEMCrypto_BuildInformation() is behaving as expected
|
// Verifies that OEMCrypto_BuildInformation() is behaving as expected
|
||||||
|
|||||||
Reference in New Issue
Block a user