Browse Source

bytestring: document that |CBS_get_optional_asn1| can have a NULL output.

On the other hand, the type-specific
|CBS_get_optional_asn1_octet_string| must have a valid pointer and we
should check this in the “present” case or there could be a lucking
crash in some user waiting for an expected value to be missing.

Change-Id: Ida40e069ac7f0e50967e3f6c6b3fc01e49bd8894
Reviewed-on: https://boringssl-review.googlesource.com/26564
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
kris/onging/CECPQ3_patch15
Adam Langley 6 years ago
committed by CQ bot account: commit-bot@chromium.org
parent
commit
d096c06b34
2 changed files with 5 additions and 4 deletions
  1. +1
    -0
      crypto/bytestring/cbs.c
  2. +4
    -4
      include/openssl/bytestring.h

+ 1
- 0
crypto/bytestring/cbs.c View File

@@ -466,6 +466,7 @@ int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
return 0; return 0;
} }
if (present) { if (present) {
assert(out);
if (!CBS_get_asn1(&child, out, CBS_ASN1_OCTETSTRING) || if (!CBS_get_asn1(&child, out, CBS_ASN1_OCTETSTRING) ||
CBS_len(&child) != 0) { CBS_len(&child) != 0) {
return 0; return 0;


+ 4
- 4
include/openssl/bytestring.h View File

@@ -240,10 +240,10 @@ OPENSSL_EXPORT int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out);
OPENSSL_EXPORT int CBS_get_asn1_bool(CBS *cbs, int *out); OPENSSL_EXPORT int CBS_get_asn1_bool(CBS *cbs, int *out);


// CBS_get_optional_asn1 gets an optional explicitly-tagged element from |cbs| // CBS_get_optional_asn1 gets an optional explicitly-tagged element from |cbs|
// tagged with |tag| and sets |*out| to its contents. If present and if
// |out_present| is not NULL, it sets |*out_present| to one, otherwise zero. It
// returns one on success, whether or not the element was present, and zero on
// decode failure.
// tagged with |tag| and sets |*out| to its contents, or ignores it if |out| is
// NULL. If present and if |out_present| is not NULL, it sets |*out_present| to
// one, otherwise zero. It returns one on success, whether or not the element
// was present, and zero on decode failure.
OPENSSL_EXPORT int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, OPENSSL_EXPORT int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present,
unsigned tag); unsigned tag);




Loading…
Cancel
Save