IteratorUsage tests: Add some canary nulled space before begin.
Hardening against write-before-begin.
This commit is contained in:
@@ -117,18 +117,19 @@ TEST(Arc4CryptTests, EncryptOutIteratorUsageTest)
|
||||
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 44> out;
|
||||
std::array<uint8_t, 47> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 44> expected =
|
||||
std::array<uint8_t, 47> expected =
|
||||
{
|
||||
0x00, 0x00, 0x00,
|
||||
0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30,
|
||||
0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 22);
|
||||
crypt.Encrypt(out.begin() + 3, data.begin(), 22);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
@@ -138,18 +139,19 @@ TEST(Arc4CryptTests, EncryptOutIteratorUsageTest)
|
||||
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 44> out;
|
||||
std::array<uint8_t, 47> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 44> expected =
|
||||
std::array<uint8_t, 47> expected =
|
||||
{
|
||||
0x00, 0x00, 0x00,
|
||||
0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30,
|
||||
0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89,
|
||||
0xef, 0xa5, 0xfa, 0xe4, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 27);
|
||||
crypt.Encrypt(out.begin() + 3, data.begin(), 27);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
@@ -165,7 +167,7 @@ TEST(Arc4CryptTests, EncryptOutIteratorUsageTest)
|
||||
std::array<uint8_t, 44> expected;
|
||||
expected.fill(0);
|
||||
|
||||
crypt.Encrypt(out.begin(), data.begin(), 0);
|
||||
crypt.Encrypt(out.begin() + 3, data.begin(), 0);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
@@ -180,16 +182,17 @@ TEST(Arc4CryptTests, DecryptOutIteratorUsageTest)
|
||||
{
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 14> out;
|
||||
std::array<uint8_t, 17> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 14> expected =
|
||||
std::array<uint8_t, 17> expected =
|
||||
{
|
||||
0x00, 0x00, 0x00,
|
||||
'A', 't', 't', 'a', 'c', 'k', ' ', 'a', 't', ' ', 'd', 'a',
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Decrypt(out.begin(), data.begin(), 12);
|
||||
crypt.Decrypt(out.begin() + 3, data.begin(), 12);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
@@ -197,16 +200,17 @@ TEST(Arc4CryptTests, DecryptOutIteratorUsageTest)
|
||||
{
|
||||
Arc4Crypt crypt(key.begin(), key.end());
|
||||
|
||||
std::array<uint8_t, 14> out;
|
||||
std::array<uint8_t, 17> out;
|
||||
out.fill(0);
|
||||
|
||||
std::array<uint8_t, 14> expected =
|
||||
std::array<uint8_t, 17> expected =
|
||||
{
|
||||
0x00, 0x00, 0x00,
|
||||
'A', 't', 't', 'a', 'c', 'k', ' ',
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
crypt.Decrypt(out.begin(), data.begin(), 7);
|
||||
crypt.Decrypt(out.begin() + 3, data.begin(), 7);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
@@ -220,7 +224,7 @@ TEST(Arc4CryptTests, DecryptOutIteratorUsageTest)
|
||||
std::array<uint8_t, 14> expected;
|
||||
expected.fill(0);
|
||||
|
||||
crypt.Decrypt(out.begin(), data.begin(), 0);
|
||||
crypt.Decrypt(out.begin() + 3, data.begin(), 0);
|
||||
|
||||
ASSERT_EQ(expected, out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user