Quellcode durchsuchen

Make CBB_len return a length, not remaining.

It switched from CBB_remaining to CBB_len partway through review, but
the semantics are still CBB_remaining. Using CBB_len allows the
len_before/len_after logic to continue working even if, in the future,
handshake messages are built on a non-fixed CBB.

Change-Id: Id466bb341a14dbbafcdb26e4c940a04181f2787d
Reviewed-on: https://boringssl-review.googlesource.com/5371
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin vor 9 Jahren
committed by Adam Langley
Ursprung
Commit
d822ed811a
3 geänderte Dateien mit 12 neuen und 10 gelöschten Zeilen
  1. +1
    -2
      crypto/bytestring/cbb.c
  2. +6
    -3
      include/openssl/bytestring.h
  3. +5
    -5
      ssl/t1_lib.c

+ 1
- 2
crypto/bytestring/cbb.c Datei anzeigen

@@ -249,9 +249,8 @@ int CBB_flush(CBB *cbb) {

size_t CBB_len(const CBB *cbb) {
assert(cbb->child == NULL);
assert(!cbb->base->can_resize);

return cbb->base->cap - cbb->base->len;
return cbb->base->len;
}

static int cbb_add_length_prefixed(CBB *cbb, CBB *out_contents,


+ 6
- 3
include/openssl/bytestring.h Datei anzeigen

@@ -284,9 +284,12 @@ OPENSSL_EXPORT int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len);
* on error. */
OPENSSL_EXPORT int CBB_flush(CBB *cbb);

/* CBB_len returns the number of bytes remaining in a fixed CBB. It is a fatal
* error to call this on a non-fixed CBB or one with any active children. This
* does not flush |cbb|. */
/* CBB_len returns the number of bytes written to |cbb|'s top-level |CBB|. It
* may be compared before and after an operation to determine how many bytes
* were written.
*
* It is a fatal error to call this on a CBB with any active children. This does
* not flush |cbb|. */
OPENSSL_EXPORT size_t CBB_len(const CBB *cbb);

/* CBB_add_u8_length_prefixed sets |*out_contents| to a new child of |cbb|. The


+ 5
- 5
ssl/t1_lib.c Datei anzeigen

@@ -1224,20 +1224,20 @@ uint8_t *ssl_add_clienthello_tlsext(SSL *s, uint8_t *const buf,
}

for (i = 0; i < kNumExtensions; i++) {
const size_t space_before = CBB_len(&cbb);
const size_t len_before = CBB_len(&cbb);
if (!kExtensions[i].add_clienthello(s, &cbb)) {
CBB_cleanup(&cbb);
OPENSSL_PUT_ERROR(SSL, ssl_add_clienthello_tlsext, ERR_R_INTERNAL_ERROR);
return NULL;
}
const size_t space_after = CBB_len(&cbb);
const size_t len_after = CBB_len(&cbb);

if (space_after != space_before) {
if (len_after != len_before) {
s->s3->tmp.extensions.sent |= (1u << i);
}
}

ret = limit - CBB_len(&cbb);
ret += CBB_len(&cbb);
CBB_cleanup(&cbb);

/* Add extended master secret. */
@@ -1513,7 +1513,7 @@ uint8_t *ssl_add_serverhello_tlsext(SSL *s, uint8_t *const buf,
}
}

ret = limit - CBB_len(&cbb);
ret += CBB_len(&cbb);
CBB_cleanup(&cbb);

if (s->s3->tmp.extended_master_secret) {


Laden…
Abbrechen
Speichern