Stop writing NUL bytes in adbkey.pub.
In N we moved some code from C to C++ without realizing that EVP_EncodedLength
includes space for a terminating NUL and EVP_EncodeBlock writes one. Because
our key reading code copes with the NUL, we never noticed.
Distinguish between the required space returned by EVP_EncodedLength and the
actual number of bytes (not including NUL) used return by EVP_EncodeBlock.
Bug: http://b/36187819
Test: hexdump of ~/.android/adbkey.pub
(cherry picked from commit 0b771b33fd)
Change-Id: I6e16b8d48d097b4054417c1d1a225bf7ece985b9
This commit is contained in:
parent
fde19425f3
commit
a761231b96
1 changed files with 6 additions and 5 deletions
|
|
@ -82,16 +82,17 @@ static bool write_public_keyfile(RSA* private_key, const std::string& private_ke
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t base64_key_length;
|
||||
if (!EVP_EncodedLength(&base64_key_length, sizeof(binary_key_data))) {
|
||||
size_t expected_length;
|
||||
if (!EVP_EncodedLength(&expected_length, sizeof(binary_key_data))) {
|
||||
LOG(ERROR) << "Public key too large to base64 encode";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string content;
|
||||
content.resize(base64_key_length);
|
||||
base64_key_length = EVP_EncodeBlock(reinterpret_cast<uint8_t*>(&content[0]), binary_key_data,
|
||||
sizeof(binary_key_data));
|
||||
content.resize(expected_length);
|
||||
size_t actual_length = EVP_EncodeBlock(reinterpret_cast<uint8_t*>(&content[0]), binary_key_data,
|
||||
sizeof(binary_key_data));
|
||||
content.resize(actual_length);
|
||||
|
||||
content += get_user_info();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue