diff options
author | 2015-06-18 23:25:07 +0000 | |
---|---|---|
committer | 2015-06-18 23:25:07 +0000 | |
commit | 9d4b5ca74c88ec79c48a23a2626fb296b06d1e70 (patch) | |
tree | b1ca48b1108b371d44fe088afaed033a8af04463 /lib/libssl/src/ssl/bs_cbb.c | |
parent | Remove Microsoft Server Gated Crypto. (diff) | |
download | wireguard-openbsd-9d4b5ca74c88ec79c48a23a2626fb296b06d1e70.tar.xz wireguard-openbsd-9d4b5ca74c88ec79c48a23a2626fb296b06d1e70.zip |
Extend the input types for CBB_add_*() to help catch bugs.
While the previous types were correct, they can silently accept bad data
via truncation or signed conversion. We now take size_t as input for
CBB_add_u*() and do a range check.
discussed with deraadt@
input + ok jsing@ miod@
Diffstat (limited to 'lib/libssl/src/ssl/bs_cbb.c')
-rw-r--r-- | lib/libssl/src/ssl/bs_cbb.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/libssl/src/ssl/bs_cbb.c b/lib/libssl/src/ssl/bs_cbb.c index e86bb926ab8..441141734bf 100644 --- a/lib/libssl/src/ssl/bs_cbb.c +++ b/lib/libssl/src/ssl/bs_cbb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbb.c,v 1.11 2015/06/13 09:24:12 doug Exp $ */ +/* $OpenBSD: bs_cbb.c,v 1.12 2015/06/18 23:25:07 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -304,8 +304,11 @@ CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents) } int -CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag) +CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned int tag) { + if (tag > UINT8_MAX) + return 0; + /* Long form identifier octets are not supported. */ if ((tag & 0x1f) == 0x1f) return 0; @@ -353,21 +356,30 @@ CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len) } int -CBB_add_u8(CBB *cbb, uint8_t value) +CBB_add_u8(CBB *cbb, size_t value) { - return cbb_add_u(cbb, value, 1); + if (value > UINT8_MAX) + return 0; + + return cbb_add_u(cbb, (uint32_t)value, 1); } int -CBB_add_u16(CBB *cbb, uint16_t value) +CBB_add_u16(CBB *cbb, size_t value) { - return cbb_add_u(cbb, value, 2); + if (value > UINT16_MAX) + return 0; + + return cbb_add_u(cbb, (uint32_t)value, 2); } int -CBB_add_u24(CBB *cbb, uint32_t value) +CBB_add_u24(CBB *cbb, size_t value) { - return cbb_add_u(cbb, value, 3); + if (value > 0xffffffUL) + return 0; + + return cbb_add_u(cbb, (uint32_t)value, 3); } int |