Fix CBS_get_any_asn1 to match the documentation.

We would assert if you pass a NULL |out| into here.

Noticed by dfess@ - thanks

Change-Id: Ia3f8fe53cb4354a354b6cdf3e3aee21eb7e1f5e9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77088
Auto-Submit: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index 23133e0..c5fff11 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -257,6 +257,18 @@
   EXPECT_EQ(CBS_ASN1_SEQUENCE, tag);
   EXPECT_EQ(Bytes("\x01\x02"), Bytes(CBS_data(&contents), CBS_len(&contents)));
 
+  CBS_init(&data, kData1, sizeof(kData1));
+  // We should be able to ignore the contents and get the tag.
+  ASSERT_TRUE(CBS_get_any_asn1(&data, NULL, &tag));
+  EXPECT_EQ(CBS_ASN1_SEQUENCE, tag);
+  // We should be able to ignore the tag and get the contents.
+  CBS_init(&data, kData1, sizeof(kData1));
+  ASSERT_TRUE(CBS_get_any_asn1(&data, &contents, NULL));
+  EXPECT_EQ(Bytes("\x01\x02"), Bytes(CBS_data(&contents), CBS_len(&contents)));
+  // We should be able to ignore both the tag and contents.
+  CBS_init(&data, kData1, sizeof(kData1));
+  ASSERT_TRUE(CBS_get_any_asn1(&data, NULL, NULL));
+
   size_t header_len;
   CBS_init(&data, kData1, sizeof(kData1));
   ASSERT_TRUE(CBS_get_any_asn1_element(&data, &contents, &tag, &header_len));
diff --git a/crypto/bytestring/cbs.cc b/crypto/bytestring/cbs.cc
index 73a9d63..fd11c5a 100644
--- a/crypto/bytestring/cbs.cc
+++ b/crypto/bytestring/cbs.cc
@@ -410,7 +410,7 @@
     return 0;
   }
 
-  if (!CBS_skip(out, header_len)) {
+  if (out && !CBS_skip(out, header_len)) {
     assert(0);
     return 0;
   }