diff options
author | David Benjamin <davidben@google.com> | 2022-12-15 17:25:11 -0500 |
---|---|---|
committer | Boringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-15 23:07:45 +0000 |
commit | 97dd962a20b1d19c9e569cf8756fbcfc48ff7c73 (patch) | |
tree | 8f755770c1fcb55b1ec89750c2a53fe2a32a75cd /crypto/asn1 | |
parent | dc139e2e6585fdd3ed8d77d41aab85c5c6c98463 (diff) | |
download | boringssl-97dd962a20b1d19c9e569cf8756fbcfc48ff7c73.zip boringssl-97dd962a20b1d19c9e569cf8756fbcfc48ff7c73.tar.gz boringssl-97dd962a20b1d19c9e569cf8756fbcfc48ff7c73.tar.bz2 |
Restore ASN1_TIME_set_string's behavior on NULL.
I inadvertently removed it, but set_string(NULL, str) would validate str
without writing an object. OpenSSL's habit of dual-use functions isn't
great (this behavior masked a bug in another project), but I apparently
even documented it in the header, so restore the behavior.
Change-Id: I8b4dbe5a2b21eb59cb20e4c845b17761329b34a1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55785
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/asn1')
-rw-r--r-- | crypto/asn1/a_gentm.c | 10 | ||||
-rw-r--r-- | crypto/asn1/a_utctm.c | 10 | ||||
-rw-r--r-- | crypto/asn1/asn1_test.cc | 12 |
3 files changed, 26 insertions, 6 deletions
diff --git a/crypto/asn1/a_gentm.c b/crypto/asn1/a_gentm.c index 0104af0..096e912 100644 --- a/crypto/asn1/a_gentm.c +++ b/crypto/asn1/a_gentm.c @@ -85,11 +85,15 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) { CBS cbs; CBS_init(&cbs, (const uint8_t *)str, len); if (!CBS_parse_generalized_time(&cbs, /*out_tm=*/NULL, - /*allow_timezone_offset=*/0) || - !ASN1_STRING_set(s, str, len)) { + /*allow_timezone_offset=*/0)) { return 0; } - s->type = V_ASN1_GENERALIZEDTIME; + if (s != NULL) { + if (!ASN1_STRING_set(s, str, len)) { + return 0; + } + s->type = V_ASN1_GENERALIZEDTIME; + } return 1; } diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c index bf09c90..d8d26ff 100644 --- a/crypto/asn1/a_utctm.c +++ b/crypto/asn1/a_utctm.c @@ -86,11 +86,15 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) { CBS cbs; CBS_init(&cbs, (const uint8_t *)str, len); if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL, - /*allow_timezone_offset=*/1) || - !ASN1_STRING_set(s, str, len)) { + /*allow_timezone_offset=*/1)) { return 0; } - s->type = V_ASN1_UTCTIME; + if (s != NULL) { + if (!ASN1_STRING_set(s, str, len)) { + return 0; + } + s->type = V_ASN1_UTCTIME; + } return 1; } diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc index fc17f40..268280f 100644 --- a/crypto/asn1/asn1_test.cc +++ b/crypto/asn1/asn1_test.cc @@ -1072,8 +1072,20 @@ TEST(ASN1Test, TimeSetString) { // Invalid inputs are rejected. EXPECT_FALSE(ASN1_UTCTIME_set_string(s.get(), "nope")); + EXPECT_FALSE(ASN1_UTCTIME_set_string(s.get(), "19700101000000Z")); EXPECT_FALSE(ASN1_GENERALIZEDTIME_set_string(s.get(), "nope")); + EXPECT_FALSE(ASN1_GENERALIZEDTIME_set_string(s.get(), "700101000000Z")); EXPECT_FALSE(ASN1_TIME_set_string(s.get(), "nope")); + + // If passed a null object, the functions validate the input without writing + // to anything. + EXPECT_TRUE(ASN1_UTCTIME_set_string(nullptr, "700101000000Z")); + EXPECT_TRUE(ASN1_TIME_set_string(nullptr, "700101000000Z")); + EXPECT_TRUE(ASN1_GENERALIZEDTIME_set_string(nullptr, "19700101000000Z")); + EXPECT_TRUE(ASN1_TIME_set_string(nullptr, "19700101000000Z")); + EXPECT_FALSE(ASN1_UTCTIME_set_string(nullptr, "nope")); + EXPECT_FALSE(ASN1_GENERALIZEDTIME_set_string(nullptr, "nope")); + EXPECT_FALSE(ASN1_TIME_set_string(nullptr, "nope")); } TEST(ASN1Test, AdjTime) { |