summaryrefslogtreecommitdiff
path: root/src/lib/libssl/bs_cbb.c
diff options
context:
space:
mode:
authorjsing <>2020-03-12 17:17:12 +0000
committerjsing <>2020-03-12 17:17:12 +0000
commit5bd2365f596fdaf1fd5d5feb218d8a3e4c99a2f1 (patch)
treecbe1f5c6f04bd5de53bc196e0f48ecf824eef897 /src/lib/libssl/bs_cbb.c
parent1ff32d7d2a793d3705647cf8a01469592503cf75 (diff)
downloadopenbsd-5bd2365f596fdaf1fd5d5feb218d8a3e4c99a2f1.tar.gz
openbsd-5bd2365f596fdaf1fd5d5feb218d8a3e4c99a2f1.tar.bz2
openbsd-5bd2365f596fdaf1fd5d5feb218d8a3e4c99a2f1.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@
Diffstat (limited to 'src/lib/libssl/bs_cbb.c')
-rw-r--r--src/lib/libssl/bs_cbb.c7
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)) {