Skip to content

Commit 4015ba6

Browse files
committed
Allow comparisons of empty ObjectIds to succeed
Prior to this change if an ObjectId with no value is compared, a null pointer dereference occurs. This allows empty ObjectIds to be compared with operator==. PiperOrigin-RevId: 290114531 Change-Id: I1fa9a31e7b2702b83e53631966fcc68a0519c30f
1 parent d0d1712 commit 4015ba6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

asylo/crypto/asn1.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ ObjectId::ObjectId(bssl::UniquePtr<ASN1_OBJECT> object)
310310
: object_(std::move(object)) {}
311311

312312
bool operator==(const ObjectId &lhs, const ObjectId &rhs) {
313+
if (lhs.object_ == nullptr || rhs.object_ == nullptr) {
314+
return lhs.object_ == rhs.object_;
315+
}
313316
return OBJ_cmp(lhs.object_.get(), rhs.object_.get()) == 0;
314317
}
315318

asylo/crypto/asn1_test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ TEST(Asn1Test, ObjectIdEquality) {
251251
}
252252
}
253253

254+
TEST(Asn1Test, ObjectIdEqualityWithEmptyOid) {
255+
ObjectId cn;
256+
ASYLO_ASSERT_OK_AND_ASSIGN(cn, ObjectId::CreateFromShortName("CN"));
257+
ObjectId empty;
258+
259+
EXPECT_THAT(cn, Not(Eq(empty)));
260+
EXPECT_THAT(cn, Ne(empty));
261+
262+
EXPECT_THAT(empty, Ne(cn));
263+
EXPECT_THAT(empty, Not(Eq(cn)));
264+
265+
EXPECT_THAT(empty, Eq(empty));
266+
EXPECT_THAT(empty, Not(Ne(empty)));
267+
}
268+
254269
TEST(Asn1Test, ObjectIdCopyConstructionPreservesEquality) {
255270
for (const auto &ids : kShortLongNidOids) {
256271
ObjectId oid;

0 commit comments

Comments
 (0)