summaryrefslogtreecommitdiff
path: root/src/crypto/bytestring
diff options
context:
space:
mode:
authorRobert Sloan <varomodt@google.com>2019-04-16 09:26:20 -0700
committerRobert Sloan <varomodt@google.com>2019-04-16 09:26:20 -0700
commitf63bd1f440905963647c68a896db0c85e8914d11 (patch)
tree5bfdfa9db8642d577ef86e52257844b934be87c4 /src/crypto/bytestring
parent4726ed3660caaf209857097358032c4257d910ad (diff)
downloadboringssl-f63bd1f440905963647c68a896db0c85e8914d11.tar.gz
external/boringssl: Sync to c9827e073f64e353c4891ecc2c73721882543ee0.android-o-mr1-iot-release-1.0.12oreo-mr1-iot-release
This includes the following changes: https://boringssl.googlesource.com/boringssl/+log/387b07b78dac785a341eeb2ff86e29393ffe8627..c9827e073f64e353c4891ecc2c73721882543ee0 Test: atest CtsLibcoreTestCases (TODO) Change-Id: Ie7c2899ac4ea374113e0fe3b76f9a4dce36ea8de
Diffstat (limited to 'src/crypto/bytestring')
-rw-r--r--src/crypto/bytestring/cbb.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/crypto/bytestring/cbb.c b/src/crypto/bytestring/cbb.c
index 7998a48e..1ddc73c6 100644
--- a/src/crypto/bytestring/cbb.c
+++ b/src/crypto/bytestring/cbb.c
@@ -44,7 +44,7 @@ static int cbb_init(CBB *cbb, uint8_t *buf, size_t cap) {
base->error = 0;
cbb->base = base;
- cbb->is_top_level = 1;
+ cbb->is_child = 0;
return 1;
}
@@ -76,11 +76,14 @@ int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len) {
}
void CBB_cleanup(CBB *cbb) {
- if (cbb->base) {
- // Only top-level |CBB|s are cleaned up. Child |CBB|s are non-owning. They
- // are implicitly discarded when the parent is flushed or cleaned up.
- assert(cbb->is_top_level);
+ // Child |CBB|s are non-owning. They are implicitly discarded and should not
+ // be used with |CBB_cleanup| or |ScopedCBB|.
+ assert(!cbb->is_child);
+ if (cbb->is_child) {
+ return;
+ }
+ if (cbb->base) {
if (cbb->base->can_resize) {
OPENSSL_free(cbb->base->buf);
}
@@ -169,7 +172,7 @@ static int cbb_buffer_add_u(struct cbb_buffer_st *base, uint64_t v,
}
int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) {
- if (!cbb->is_top_level) {
+ if (cbb->is_child) {
return 0;
}
@@ -310,6 +313,7 @@ static int cbb_add_length_prefixed(CBB *cbb, CBB *out_contents,
OPENSSL_memset(prefix_bytes, 0, len_len);
OPENSSL_memset(out_contents, 0, sizeof(CBB));
out_contents->base = cbb->base;
+ out_contents->is_child = 1;
cbb->child = out_contents;
cbb->child->offset = offset;
cbb->child->pending_len_len = len_len;
@@ -381,6 +385,7 @@ int CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned tag) {
OPENSSL_memset(out_contents, 0, sizeof(CBB));
out_contents->base = cbb->base;
+ out_contents->is_child = 1;
cbb->child = out_contents;
cbb->child->offset = offset;
cbb->child->pending_len_len = 1;