diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2015-09-01 13:35:40 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2015-09-01 13:35:40 +0000 |
commit | d24958d230eedfdfda6024da0587fdc4a7191bdc (patch) | |
tree | 674385fbb379a68a1bdcf079f0608f22f6e57f7e /lib | |
parent | 9a4112dce035fbe499ef45b95d20ed7214a1eb0e (diff) |
Make it always safe to call CBB_cleanup() providing that CBB_init() or
CBB_init_fixed() have been attempted.
ok doug@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libssl/src/ssl/bs_cbb.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/libssl/src/ssl/bs_cbb.c b/lib/libssl/src/ssl/bs_cbb.c index 441141734bf..3f8e08e0e35 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.12 2015/06/18 23:25:07 doug Exp $ */ +/* $OpenBSD: bs_cbb.c,v 1.13 2015/09/01 13:35:39 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -36,9 +36,9 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap) base->cap = cap; base->can_resize = 1; - memset(cbb, 0, sizeof(*cbb)); cbb->base = base; cbb->is_top_level = 1; + return 1; } @@ -47,6 +47,8 @@ CBB_init(CBB *cbb, size_t initial_capacity) { uint8_t *buf = NULL; + memset(cbb, 0, sizeof(*cbb)); + if (initial_capacity > 0) { if ((buf = malloc(initial_capacity)) == NULL) return 0; @@ -56,16 +58,20 @@ CBB_init(CBB *cbb, size_t initial_capacity) free(buf); return 0; } + return 1; } int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len) { + memset(cbb, 0, sizeof(*cbb)); + if (!cbb_init(cbb, buf, len)) return 0; cbb->base->can_resize = 0; + return 1; } |