summaryrefslogtreecommitdiff
path: root/sshbuf.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2017-10-04 11:23:58 +0100
committerColin Watson <cjwatson@debian.org>2017-10-04 11:23:58 +0100
commit62f54f20bf351468e0124f63cc2902ee40d9b0e9 (patch)
tree3e090f2711b94ca5029d3fa3e8047b1ed1448b1f /sshbuf.c
parent6fabaf6fd9b07cc8bc6a17c9c4a5b76849cfc874 (diff)
parent66bf74a92131b7effe49fb0eefe5225151869dc5 (diff)
Import openssh_7.6p1.orig.tar.gz
Diffstat (limited to 'sshbuf.c')
-rw-r--r--sshbuf.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sshbuf.c b/sshbuf.c
index cbf7ed4a4..de783a363 100644
--- a/sshbuf.c
+++ b/sshbuf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshbuf.c,v 1.8 2016/11/25 23:22:04 djm Exp $ */ 1/* $OpenBSD: sshbuf.c,v 1.11 2017/06/01 06:58:25 djm 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 }
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 }
@@ -391,6 +391,9 @@ sshbuf_consume(struct sshbuf *buf, size_t len)
391 if (len > sshbuf_len(buf)) 391 if (len > sshbuf_len(buf))
392 return SSH_ERR_MESSAGE_INCOMPLETE; 392 return SSH_ERR_MESSAGE_INCOMPLETE;
393 buf->off += len; 393 buf->off += len;
394 /* deal with empty buffer */
395 if (buf->off == buf->size)
396 buf->off = buf->size = 0;
394 SSHBUF_TELL("done"); 397 SSHBUF_TELL("done");
395 return 0; 398 return 0;
396} 399}