From f2b32a2de2c0bb4f93e009ea409cfe6f1139f44e Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 2 Nov 2014 17:32:40 -0500 Subject: [PATCH] Switch ssl3_send_channel_id to BN_bn2bin_padded. Check the return value while we're here. This avoids some arithmetic and appease scan-build's dead assignment flagger. Change-Id: If3615076e091eb44b9e3e9d50cd64f80e645337e Reviewed-on: https://boringssl-review.googlesource.com/2204 Reviewed-by: Adam Langley --- ssl/s3_clnt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c index 64bccfaa3..0806d7799 100644 --- a/ssl/s3_clnt.c +++ b/ssl/s3_clnt.c @@ -2699,11 +2699,12 @@ int ssl3_send_channel_id(SSL *s) /* The first byte of public_key will be 0x4, denoting an uncompressed key. */ memcpy(d, public_key + 1, 64); d += 64; - memset(d, 0, 2 * 32); - BN_bn2bin(sig->r, d + 32 - BN_num_bytes(sig->r)); - d += 32; - BN_bn2bin(sig->s, d + 32 - BN_num_bytes(sig->s)); - d += 32; + if (!BN_bn2bin_padded(d, 32, sig->r) || + !BN_bn2bin_padded(d + 32, 32, sig->s)) + { + OPENSSL_PUT_ERROR(SSL, ssl3_send_channel_id, ERR_R_INTERNAL_ERROR); + goto err; + } s->state = SSL3_ST_CW_CHANNEL_ID_B; s->init_num = 4 + 2 + 2 + TLSEXT_CHANNEL_ID_SIZE;