Fixes an issue when the owner key is empty chrome would crash trying to access bogus memory.

BUG=128410
TEST=OwnerKeyUtilsTest.ImportPublicKeyFailed

Review URL: https://chromiumcodereview.appspot.com/10399104

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138238 0039d316-1c4b-4281-b951-d872f2087c98
parent ec4252cc
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -123,6 +123,12 @@ bool OwnerKeyUtilsImpl::ImportPublicKey(const FilePath& key_file, ...@@ -123,6 +123,12 @@ bool OwnerKeyUtilsImpl::ImportPublicKey(const FilePath& key_file,
int32 safe_file_size = static_cast<int32>(file_size); int32 safe_file_size = static_cast<int32>(file_size);
output->resize(safe_file_size); output->resize(safe_file_size);
if (safe_file_size == 0) {
LOG(WARNING) << "Public key file is empty. This seems wrong.";
return false;
}
// Get the key data off of disk // Get the key data off of disk
int data_read = file_util::ReadFile(key_file, int data_read = file_util::ReadFile(key_file,
reinterpret_cast<char*>(&(output->at(0))), reinterpret_cast<char*>(&(output->at(0))),
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -65,4 +65,20 @@ TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) { ...@@ -65,4 +65,20 @@ TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) {
} }
} }
TEST_F(OwnerKeyUtilsTest, ImportPublicKeyFailed) {
ScopedTempDir tmpdir;
FilePath tmpfile;
ASSERT_TRUE(tmpdir.CreateUniqueTempDir());
// First test the case where the file is missing which should fail.
std::vector<uint8> from_disk;
ASSERT_FALSE(utils_->ImportPublicKey(tmpfile, &from_disk));
// Next try empty file. This should fail and the array should be empty.
from_disk.resize(10);
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile));
ASSERT_FALSE(utils_->ImportPublicKey(tmpfile, &from_disk));
ASSERT_FALSE(from_disk.size());
}
} // namespace chromeos } // namespace chromeos
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