Commit 09b6721b authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Fixed normalization of certificate subject for in-file certificates

Bug: 819793
Change-Id: Ic42c128ba5f30208332f17100d24a61ee320c3db
Reviewed-on: https://chromium-review.googlesource.com/1012190Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550677}
parent be978d74
...@@ -110,6 +110,10 @@ base::string16 GetSubjectNameInFile(const base::FilePath& filename) { ...@@ -110,6 +110,10 @@ base::string16 GetSubjectNameInFile(const base::FilePath& filename) {
return base::string16(); return base::string16();
} }
// The subject name is normalized because it can contain trailing null
// characters.
internal::NormalizeCertificateSubject(&subject_name);
return subject_name; return subject_name;
} }
...@@ -217,10 +221,6 @@ void GetCatalogCertificateInfo(const base::FilePath& filename, ...@@ -217,10 +221,6 @@ void GetCatalogCertificateInfo(const base::FilePath& filename,
certificate_info->type = CertificateType::CERTIFICATE_IN_CATALOG; certificate_info->type = CertificateType::CERTIFICATE_IN_CATALOG;
certificate_info->path = catalog_path; certificate_info->path = catalog_path;
certificate_info->subject = subject; certificate_info->subject = subject;
// The subject name is normalized because it can contain trailing null
// characters.
internal::NormalizeCertificateSubject(certificate_info);
} }
} // namespace } // namespace
...@@ -329,10 +329,10 @@ bool GetModuleImageSizeAndTimeDateStamp(const base::FilePath& path, ...@@ -329,10 +329,10 @@ bool GetModuleImageSizeAndTimeDateStamp(const base::FilePath& path,
namespace internal { namespace internal {
void NormalizeCertificateSubject(CertificateInfo* certificate_info) { void NormalizeCertificateSubject(base::string16* subject) {
size_t first_null = certificate_info->subject.find(L'\0'); size_t first_null = subject->find(L'\0');
if (first_null != base::string16::npos) if (first_null != base::string16::npos)
certificate_info->subject.resize(first_null); subject->resize(first_null);
} }
} // namespace internal } // namespace internal
...@@ -74,7 +74,7 @@ namespace internal { ...@@ -74,7 +74,7 @@ namespace internal {
// Removes trailing null characters from the certificate's subject. // Removes trailing null characters from the certificate's subject.
// Exposed for testing. // Exposed for testing.
void NormalizeCertificateSubject(CertificateInfo* certificate_info); void NormalizeCertificateSubject(base::string16* subject);
} // namespace internal } // namespace internal
......
...@@ -171,14 +171,12 @@ TEST(ModuleInfoUtilTest, InvalidNTHeader) { ...@@ -171,14 +171,12 @@ TEST(ModuleInfoUtilTest, InvalidNTHeader) {
} }
TEST(ModuleInfoUtilTest, NormalizeCertificateSubject) { TEST(ModuleInfoUtilTest, NormalizeCertificateSubject) {
CertificateInfo test_case; base::string16 test_case = base::string16(L"signer\0", 7);
test_case.subject = base::string16(L"signer\0", 7); EXPECT_EQ(7u, test_case.length());
EXPECT_EQ(7u, test_case.subject.length());
CertificateInfo expected; base::string16 expected = L"signer";
expected.subject = L"signer";
internal::NormalizeCertificateSubject(&test_case); internal::NormalizeCertificateSubject(&test_case);
EXPECT_EQ(test_case.subject, expected.subject); EXPECT_EQ(test_case, 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