bytestring: Test out_header_len != NULL before writing.

The documentation for |CBS_get_any_asn1_element| says that
|out_header_len| may be NULL, but in the case of an indefinite-length
element it would be written unconditionally.

Thanks to Doug Hogan for noticing this.

Change-Id: I17609b3465df73d42dd9efd75e783159aa99a59b
Reviewed-on: https://boringssl-review.googlesource.com/4993
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Adam Langley 2015-06-02 15:48:37 -07:00
parent ba5934b77f
commit 0976096224

View File

@ -195,7 +195,9 @@ int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
if ((tag & CBS_ASN1_CONSTRUCTED) != 0 && num_bytes == 0) {
/* indefinite length */
*out_header_len = 2;
if (out_header_len != NULL) {
*out_header_len = 2;
}
return CBS_get_bytes(cbs, out, 2);
}