diff options
author | jsing <> | 2020-03-12 17:17:12 +0000 |
---|---|---|
committer | jsing <> | 2020-03-12 17:17:12 +0000 |
commit | 175ca43e2c7b1e7714399153118edc54b4268792 (patch) | |
tree | cbe1f5c6f04bd5de53bc196e0f48ecf824eef897 | |
parent | 755b6e0d6d04ef513897a809271a846b984da4e8 (diff) | |
download | openbsd-175ca43e2c7b1e7714399153118edc54b4268792.tar.gz openbsd-175ca43e2c7b1e7714399153118edc54b4268792.tar.bz2 openbsd-175ca43e2c7b1e7714399153118edc54b4268792.zip |
Use calloc() rather than malloc() when allocating initial CBB buffer.
CBB uses recallocarray() to expand buffers, however was still using
malloc() for the initial buffer, which could result in memory being leaked
in incorrect use cases.
While here also use calloc() to allocate internal structs.
ok inoguchi@ tb@
-rw-r--r-- | src/lib/libssl/bs_cbb.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c index a34e822c94..16e17fb70f 100644 --- a/src/lib/libssl/bs_cbb.c +++ b/src/lib/libssl/bs_cbb.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bs_cbb.c,v 1.20 2019/01/23 22:20:40 beck Exp $ */ | 1 | /* $OpenBSD: bs_cbb.c,v 1.21 2020/03/12 17:17:12 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014, Google Inc. | 3 | * Copyright (c) 2014, Google Inc. |
4 | * | 4 | * |
@@ -28,8 +28,7 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap) | |||
28 | { | 28 | { |
29 | struct cbb_buffer_st *base; | 29 | struct cbb_buffer_st *base; |
30 | 30 | ||
31 | base = malloc(sizeof(struct cbb_buffer_st)); | 31 | if ((base = calloc(1, sizeof(struct cbb_buffer_st))) == NULL) |
32 | if (base == NULL) | ||
33 | return 0; | 32 | return 0; |
34 | 33 | ||
35 | base->buf = buf; | 34 | base->buf = buf; |
@@ -53,7 +52,7 @@ CBB_init(CBB *cbb, size_t initial_capacity) | |||
53 | if (initial_capacity == 0) | 52 | if (initial_capacity == 0) |
54 | initial_capacity = CBB_INITIAL_SIZE; | 53 | initial_capacity = CBB_INITIAL_SIZE; |
55 | 54 | ||
56 | if ((buf = malloc(initial_capacity)) == NULL) | 55 | if ((buf = calloc(1, initial_capacity)) == NULL) |
57 | return 0; | 56 | return 0; |
58 | 57 | ||
59 | if (!cbb_init(cbb, buf, initial_capacity)) { | 58 | if (!cbb_init(cbb, buf, initial_capacity)) { |