Commit b281e7c6 authored by mnissler@chromium.org's avatar mnissler@chromium.org

Properly handle zero-sized fields in the PReg parser.

For zero-sized values, we'd previously pass NULL to std::copy, which is
not OK though if the number of elements to copy is 0. Avoid the copy
altogether and cover this situation in the unit test.

BUG=None
R=joaodasilva@chromium.org

Review URL: https://codereview.chromium.org/23704008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223345 0039d316-1c4b-4281-b951-d872f2087c98
parent 38badab8
......@@ -64,12 +64,13 @@ int NextChar(const uint8** cursor, const uint8* end) {
// Reads a fixed-size field from a PReg file.
bool ReadFieldBinary(const uint8** cursor,
const uint8* end,
int size,
uint32 size,
uint8* data) {
if (!size)
return false;
if (size == 0)
return true;
const uint8* field_end = *cursor + size;
if (field_end > end)
if (field_end <= *cursor || field_end > end)
return false;
std::copy(*cursor, field_end, data);
*cursor = field_end;
......
......@@ -43,8 +43,9 @@ testing::AssertionResult RegistryDictEquals(const RegistryDict& a,
if (iter_value_a->first != iter_value_b->first ||
!base::Value::Equals(iter_value_a->second, iter_value_b->second)) {
return testing::AssertionFailure()
<< "Value mismatch " << iter_value_a->first
<< " vs. " << iter_value_b->first;
<< "Value mismatch "
<< iter_value_a->first << "=" << *iter_value_a->second
<< " vs. " << iter_value_b->first << "=" << *iter_value_b->second;
}
}
......@@ -108,6 +109,7 @@ TEST(PRegParserWinTest, TestParseFile) {
expected.SetKey("RestoreOnStartupURLs", startup_urls.Pass());
SetInteger(&expected, "ShowHomeButton", 1);
SetString(&expected, "Snowman", "\xE2\x98\x83");
SetString(&expected, "Empty", "");
EXPECT_TRUE(RegistryDictEquals(dict, expected));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment