summaryrefslogtreecommitdiff
path: root/sshbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshbuf.c')
-rw-r--r--sshbuf.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sshbuf.c b/sshbuf.c
index 652c99a21..b7a90b5c2 100644
--- a/sshbuf.c
+++ b/sshbuf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshbuf.c,v 1.9 2017/05/26 20:34:49 markus Exp $ */ 1/* $OpenBSD: sshbuf.c,v 1.10 2017/05/31 09:15:42 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller 3 * Copyright (c) 2011 Damien Miller
4 * 4 *
@@ -193,15 +193,16 @@ sshbuf_reset(struct sshbuf *buf)
193 buf->off = buf->size; 193 buf->off = buf->size;
194 return; 194 return;
195 } 195 }
196 if (sshbuf_check_sanity(buf) == 0) 196 (void) sshbuf_check_sanity(buf);
197 explicit_bzero(buf->d, buf->alloc);
198 buf->off = buf->size = 0; 197 buf->off = buf->size = 0;
199 if (buf->alloc != SSHBUF_SIZE_INIT) { 198 if (buf->alloc != SSHBUF_SIZE_INIT) {
200 if ((d = realloc(buf->d, SSHBUF_SIZE_INIT)) != NULL) { 199 if ((d = recallocarray(buf->d, buf->alloc, SSHBUF_SIZE_INIT,
200 1)) != NULL) {
201 buf->cd = buf->d = d; 201 buf->cd = buf->d = d;
202 buf->alloc = SSHBUF_SIZE_INIT; 202 buf->alloc = SSHBUF_SIZE_INIT;
203 } 203 }
204 } 204 } else
205 explicit_bzero(buf->d, SSHBUF_SIZE_INIT);
205} 206}
206 207
207size_t 208size_t
@@ -253,9 +254,8 @@ sshbuf_set_max_size(struct sshbuf *buf, size_t max_size)
253 rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC); 254 rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC);
254 if (rlen > max_size) 255 if (rlen > max_size)
255 rlen = max_size; 256 rlen = max_size;
256 explicit_bzero(buf->d + buf->size, buf->alloc - buf->size);
257 SSHBUF_DBG(("new alloc = %zu", rlen)); 257 SSHBUF_DBG(("new alloc = %zu", rlen));
258 if ((dp = realloc(buf->d, rlen)) == NULL) 258 if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL)
259 return SSH_ERR_ALLOC_FAIL; 259 return SSH_ERR_ALLOC_FAIL;
260 buf->cd = buf->d = dp; 260 buf->cd = buf->d = dp;
261 buf->alloc = rlen; 261 buf->alloc = rlen;
@@ -344,7 +344,7 @@ sshbuf_allocate(struct sshbuf *buf, size_t len)
344 if (rlen > buf->max_size) 344 if (rlen > buf->max_size)
345 rlen = buf->alloc + need; 345 rlen = buf->alloc + need;
346 SSHBUF_DBG(("adjusted rlen %zu", rlen)); 346 SSHBUF_DBG(("adjusted rlen %zu", rlen));
347 if ((dp = realloc(buf->d, rlen)) == NULL) { 347 if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL) {
348 SSHBUF_DBG(("realloc fail")); 348 SSHBUF_DBG(("realloc fail"));
349 return SSH_ERR_ALLOC_FAIL; 349 return SSH_ERR_ALLOC_FAIL;
350 } 350 }