upstream commit

use explicit_bzero() more liberally in the buffer code; ok
 deraadt

Upstream-ID: 0ece37069fd66bc6e4f55eb1321f93df372b65bf
This commit is contained in:
djm@openbsd.org 2016-01-12 23:42:54 +00:00 committed by Damien Miller
parent 4626cbaf78
commit 9a728cc918
2 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sshbuf-getput-crypto.c,v 1.4 2015/01/14 15:02:39 djm Exp $ */ /* $OpenBSD: sshbuf-getput-crypto.c,v 1.5 2016/01/12 23:42:54 djm Exp $ */
/* /*
* Copyright (c) 2011 Damien Miller * Copyright (c) 2011 Damien Miller
* *
@ -158,10 +158,10 @@ sshbuf_put_bignum2(struct sshbuf *buf, const BIGNUM *v)
if (len > 0 && (d[1] & 0x80) != 0) if (len > 0 && (d[1] & 0x80) != 0)
prepend = 1; prepend = 1;
if ((r = sshbuf_put_string(buf, d + 1 - prepend, len + prepend)) < 0) { if ((r = sshbuf_put_string(buf, d + 1 - prepend, len + prepend)) < 0) {
bzero(d, sizeof(d)); explicit_bzero(d, sizeof(d));
return r; return r;
} }
bzero(d, sizeof(d)); explicit_bzero(d, sizeof(d));
return 0; return 0;
} }
@ -177,13 +177,13 @@ sshbuf_put_bignum1(struct sshbuf *buf, const BIGNUM *v)
if (BN_bn2bin(v, d) != (int)len_bytes) if (BN_bn2bin(v, d) != (int)len_bytes)
return SSH_ERR_INTERNAL_ERROR; /* Shouldn't happen */ return SSH_ERR_INTERNAL_ERROR; /* Shouldn't happen */
if ((r = sshbuf_reserve(buf, len_bytes + 2, &dp)) < 0) { if ((r = sshbuf_reserve(buf, len_bytes + 2, &dp)) < 0) {
bzero(d, sizeof(d)); explicit_bzero(d, sizeof(d));
return r; return r;
} }
POKE_U16(dp, len_bits); POKE_U16(dp, len_bits);
if (len_bytes != 0) if (len_bytes != 0)
memcpy(dp + 2, d, len_bytes); memcpy(dp + 2, d, len_bytes);
bzero(d, sizeof(d)); explicit_bzero(d, sizeof(d));
return 0; return 0;
} }
@ -210,7 +210,7 @@ sshbuf_put_ec(struct sshbuf *buf, const EC_POINT *v, const EC_GROUP *g)
} }
BN_CTX_free(bn_ctx); BN_CTX_free(bn_ctx);
ret = sshbuf_put_string(buf, d, len); ret = sshbuf_put_string(buf, d, len);
bzero(d, len); explicit_bzero(d, len);
return ret; return ret;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sshbuf.c,v 1.5 2015/12/11 04:21:12 mmcc Exp $ */ /* $OpenBSD: sshbuf.c,v 1.6 2016/01/12 23:42:54 djm Exp $ */
/* /*
* Copyright (c) 2011 Damien Miller * Copyright (c) 2011 Damien Miller
* *
@ -134,7 +134,7 @@ sshbuf_fromb(struct sshbuf *buf)
void void
sshbuf_init(struct sshbuf *ret) sshbuf_init(struct sshbuf *ret)
{ {
bzero(ret, sizeof(*ret)); explicit_bzero(ret, sizeof(*ret));
ret->alloc = SSHBUF_SIZE_INIT; ret->alloc = SSHBUF_SIZE_INIT;
ret->max_size = SSHBUF_SIZE_MAX; ret->max_size = SSHBUF_SIZE_MAX;
ret->readonly = 0; ret->readonly = 0;
@ -178,7 +178,7 @@ sshbuf_free(struct sshbuf *buf)
explicit_bzero(buf->d, buf->alloc); explicit_bzero(buf->d, buf->alloc);
free(buf->d); free(buf->d);
} }
bzero(buf, sizeof(*buf)); explicit_bzero(buf, sizeof(*buf));
if (!dont_free) if (!dont_free)
free(buf); free(buf);
} }
@ -194,7 +194,7 @@ sshbuf_reset(struct sshbuf *buf)
return; return;
} }
if (sshbuf_check_sanity(buf) == 0) if (sshbuf_check_sanity(buf) == 0)
bzero(buf->d, buf->alloc); explicit_bzero(buf->d, buf->alloc);
buf->off = buf->size = 0; buf->off = buf->size = 0;
if (buf->alloc != SSHBUF_SIZE_INIT) { if (buf->alloc != SSHBUF_SIZE_INIT) {
if ((d = realloc(buf->d, SSHBUF_SIZE_INIT)) != NULL) { if ((d = realloc(buf->d, SSHBUF_SIZE_INIT)) != NULL) {
@ -253,7 +253,7 @@ sshbuf_set_max_size(struct sshbuf *buf, size_t max_size)
rlen = roundup(buf->size, SSHBUF_SIZE_INC); rlen = roundup(buf->size, SSHBUF_SIZE_INC);
if (rlen > max_size) if (rlen > max_size)
rlen = max_size; rlen = max_size;
bzero(buf->d + buf->size, buf->alloc - buf->size); explicit_bzero(buf->d + buf->size, buf->alloc - buf->size);
SSHBUF_DBG(("new alloc = %zu", rlen)); SSHBUF_DBG(("new alloc = %zu", rlen));
if ((dp = realloc(buf->d, rlen)) == NULL) if ((dp = realloc(buf->d, rlen)) == NULL)
return SSH_ERR_ALLOC_FAIL; return SSH_ERR_ALLOC_FAIL;