Commit 2cbe71ae authored by Matt Mueller's avatar Matt Mueller Committed by Commit Bot

Move out_result_ to first member in net::CertPathBuilder.

CertPathBuilder::cert_path_iter_ is constructed with a pointer to
out_result_, so out_result_ must be earlier in the member list to ensure
it is constructed before cert_path_iter_ tries to access it.

Bug: 997340,991247
Change-Id: I93137a16e0022db00d71b91b6636e42d6f39f2ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769701Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: Matt Mueller <mattm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690154}
parent f39b7b73
...@@ -192,6 +192,10 @@ class NET_EXPORT CertPathBuilder { ...@@ -192,6 +192,10 @@ class NET_EXPORT CertPathBuilder {
private: private:
void AddResultPath(std::unique_ptr<CertPathBuilderResultPath> result_path); void AddResultPath(std::unique_ptr<CertPathBuilderResultPath> result_path);
// |out_result_| may be referenced by other members, so should be initialized
// first.
Result out_result_;
std::unique_ptr<CertPathIter> cert_path_iter_; std::unique_ptr<CertPathIter> cert_path_iter_;
CertPathBuilderDelegate* delegate_; CertPathBuilderDelegate* delegate_;
const der::GeneralizedTime time_; const der::GeneralizedTime time_;
...@@ -203,8 +207,6 @@ class NET_EXPORT CertPathBuilder { ...@@ -203,8 +207,6 @@ class NET_EXPORT CertPathBuilder {
uint32_t max_iteration_count_ = 0; uint32_t max_iteration_count_ = 0;
base::TimeTicks deadline_; base::TimeTicks deadline_;
Result out_result_;
DISALLOW_COPY_AND_ASSIGN(CertPathBuilder); DISALLOW_COPY_AND_ASSIGN(CertPathBuilder);
}; };
......
...@@ -117,6 +117,49 @@ class AsyncCertIssuerSourceStatic : public CertIssuerSource { ...@@ -117,6 +117,49 @@ class AsyncCertIssuerSourceStatic : public CertIssuerSource {
return ::testing::AssertionSuccess(); return ::testing::AssertionSuccess();
} }
const void* kKey = &kKey;
class TrustStoreThatStoresUserData : public TrustStore {
public:
class Data : public base::SupportsUserData::Data {
public:
explicit Data(int value) : value(value) {}
int value = 0;
};
// TrustStore implementation:
void SyncGetIssuersOf(const ParsedCertificate* cert,
ParsedCertificateList* issuers) override {}
void GetTrust(const scoped_refptr<ParsedCertificate>& cert,
CertificateTrust* trust,
base::SupportsUserData* debug_data) const override {
debug_data->SetUserData(kKey, std::make_unique<Data>(1234));
}
};
TEST(PathBuilderResultUserDataTest, ModifyUserDataInConstructor) {
scoped_refptr<ParsedCertificate> a_by_b;
ASSERT_TRUE(ReadTestCert("multi-root-A-by-B.pem", &a_by_b));
SimplePathBuilderDelegate delegate(
1024, SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1);
der::GeneralizedTime verify_time = {2017, 3, 1, 0, 0, 0};
TrustStoreThatStoresUserData trust_store;
// |trust_store| will unconditionally store user data in the
// CertPathBuilder::Result. This ensures that the Result object has been
// initialized before the first GetTrust call occurs (otherwise the test will
// crash or fail on ASAN bots).
CertPathBuilder path_builder(
a_by_b, &trust_store, &delegate, verify_time, KeyPurpose::ANY_EKU,
InitialExplicitPolicy::kFalse, {AnyPolicy()},
InitialPolicyMappingInhibit::kFalse, InitialAnyPolicyInhibit::kFalse);
CertPathBuilder::Result result = path_builder.Run();
auto* data = static_cast<TrustStoreThatStoresUserData::Data*>(
result.GetUserData(kKey));
ASSERT_TRUE(data);
EXPECT_EQ(1234, data->value);
}
class PathBuilderMultiRootTest : public ::testing::Test { class PathBuilderMultiRootTest : public ::testing::Test {
public: public:
PathBuilderMultiRootTest() PathBuilderMultiRootTest()
......
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