Test clearing out-of-bounds bits with ASN1_BIT_STRING_set_bit I was doing some experiments, had a bug in this case, and our tests didn't notice. Bug: 42290311 Change-Id: I3bf8e9dec2abac455ef59c4cb809ec10af370243 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/86127 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Lily Chen <chlily@google.com> Commit-Queue: Lily Chen <chlily@google.com>
diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc index dced405..e93e356 100644 --- a/crypto/asn1/asn1_test.cc +++ b/crypto/asn1/asn1_test.cc
@@ -889,6 +889,11 @@ EXPECT_EQ(0, ASN1_BIT_STRING_get_bit(val.get(), 3)); EXPECT_EQ(0, ASN1_BIT_STRING_get_bit(val.get(), 4)); + // Bits that were already out-of-bounds and clear may be cleared. This is a + // no-op. + ASSERT_TRUE(ASN1_BIT_STRING_set_bit(val.get(), 100, 0)); + TestSerialize(val.get(), i2d_ASN1_BIT_STRING, kBitString1); + // Bits may be set beyond the end of the string. ASSERT_TRUE(ASN1_BIT_STRING_set_bit(val.get(), 63, 1)); static const uint8_t kBitStringLong[] = {0x03, 0x09, 0x00, 0x80, 0x00, 0x00,