diff options
-rw-r--r-- | auth2-pubkey.c | 9 | ||||
-rw-r--r-- | authfile.c | 16 | ||||
-rw-r--r-- | bitmap.c | 2 | ||||
-rw-r--r-- | clientloop.c | 10 | ||||
-rw-r--r-- | hostfile.c | 4 | ||||
-rw-r--r-- | krl.c | 4 | ||||
-rw-r--r-- | misc.c | 4 | ||||
-rw-r--r-- | scp.c | 8 | ||||
-rw-r--r-- | session.c | 10 | ||||
-rw-r--r-- | ssh-pkcs11.c | 6 | ||||
-rw-r--r-- | sshbuf.c | 16 | ||||
-rw-r--r-- | sshkey.c | 7 | ||||
-rw-r--r-- | utf8.c | 4 | ||||
-rw-r--r-- | xmalloc.c | 14 | ||||
-rw-r--r-- | xmalloc.h | 3 |
15 files changed, 58 insertions, 59 deletions
diff --git a/auth2-pubkey.c b/auth2-pubkey.c index 7a6280f8d..271dbaf65 100644 --- a/auth2-pubkey.c +++ b/auth2-pubkey.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth2-pubkey.c,v 1.65 2017/05/30 14:29:59 markus Exp $ */ | 1 | /* $OpenBSD: auth2-pubkey.c,v 1.66 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -1156,9 +1156,10 @@ auth2_record_userkey(Authctxt *authctxt, struct sshkey *key) | |||
1156 | struct sshkey **tmp; | 1156 | struct sshkey **tmp; |
1157 | 1157 | ||
1158 | if (authctxt->nprev_userkeys >= INT_MAX || | 1158 | if (authctxt->nprev_userkeys >= INT_MAX || |
1159 | (tmp = reallocarray(authctxt->prev_userkeys, | 1159 | (tmp = recallocarray(authctxt->prev_userkeys, |
1160 | authctxt->nprev_userkeys + 1, sizeof(*tmp))) == NULL) | 1160 | authctxt->nprev_userkeys, authctxt->nprev_userkeys + 1, |
1161 | fatal("%s: reallocarray failed", __func__); | 1161 | sizeof(*tmp))) == NULL) |
1162 | fatal("%s: recallocarray failed", __func__); | ||
1162 | authctxt->prev_userkeys = tmp; | 1163 | authctxt->prev_userkeys = tmp; |
1163 | authctxt->prev_userkeys[authctxt->nprev_userkeys] = key; | 1164 | authctxt->prev_userkeys[authctxt->nprev_userkeys] = key; |
1164 | authctxt->nprev_userkeys++; | 1165 | authctxt->nprev_userkeys++; |
diff --git a/authfile.c b/authfile.c index af4190eeb..3481e0b04 100644 --- a/authfile.c +++ b/authfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: authfile.c,v 1.125 2017/05/30 08:49:32 markus Exp $ */ | 1 | /* $OpenBSD: authfile.c,v 1.126 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -100,25 +100,13 @@ sshkey_load_file(int fd, struct sshbuf *blob) | |||
100 | u_char buf[1024]; | 100 | u_char buf[1024]; |
101 | size_t len; | 101 | size_t len; |
102 | struct stat st; | 102 | struct stat st; |
103 | int r, dontmax = 0; | 103 | int r; |
104 | 104 | ||
105 | if (fstat(fd, &st) < 0) | 105 | if (fstat(fd, &st) < 0) |
106 | return SSH_ERR_SYSTEM_ERROR; | 106 | return SSH_ERR_SYSTEM_ERROR; |
107 | if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && | 107 | if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && |
108 | st.st_size > MAX_KEY_FILE_SIZE) | 108 | st.st_size > MAX_KEY_FILE_SIZE) |
109 | return SSH_ERR_INVALID_FORMAT; | 109 | return SSH_ERR_INVALID_FORMAT; |
110 | /* | ||
111 | * Pre-allocate the buffer used for the key contents and clamp its | ||
112 | * maximum size. This ensures that key contents are never leaked via | ||
113 | * implicit realloc() in the sshbuf code. | ||
114 | */ | ||
115 | if ((st.st_mode & S_IFREG) == 0 || st.st_size <= 0) { | ||
116 | st.st_size = 64*1024; /* 64k ought to be enough for anybody. :) */ | ||
117 | dontmax = 1; | ||
118 | } | ||
119 | if ((r = sshbuf_allocate(blob, st.st_size)) != 0 || | ||
120 | (dontmax && (r = sshbuf_set_max_size(blob, st.st_size)) != 0)) | ||
121 | return r; | ||
122 | for (;;) { | 110 | for (;;) { |
123 | if ((len = atomicio(read, fd, buf, sizeof(buf))) == 0) { | 111 | if ((len = atomicio(read, fd, buf, sizeof(buf))) == 0) { |
124 | if (errno == EPIPE) | 112 | if (errno == EPIPE) |
@@ -87,7 +87,7 @@ reserve(struct bitmap *b, u_int n) | |||
87 | return -1; /* invalid */ | 87 | return -1; /* invalid */ |
88 | nlen = (n / BITMAP_BITS) + 1; | 88 | nlen = (n / BITMAP_BITS) + 1; |
89 | if (b->len < nlen) { | 89 | if (b->len < nlen) { |
90 | if ((tmp = reallocarray(b->d, nlen, BITMAP_BYTES)) == NULL) | 90 | if ((tmp = recallocarray(b->d, b->len, nlen, BITMAP_BYTES)) == NULL) |
91 | return -1; | 91 | return -1; |
92 | b->d = tmp; | 92 | b->d = tmp; |
93 | memset(b->d + b->len, 0, (nlen - b->len) * BITMAP_BYTES); | 93 | memset(b->d + b->len, 0, (nlen - b->len) * BITMAP_BYTES); |
diff --git a/clientloop.c b/clientloop.c index 33d6fa908..612838376 100644 --- a/clientloop.c +++ b/clientloop.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: clientloop.c,v 1.298 2017/05/31 07:00:13 markus Exp $ */ | 1 | /* $OpenBSD: clientloop.c,v 1.299 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -1812,9 +1812,9 @@ hostkeys_find(struct hostkey_foreach_line *l, void *_ctx) | |||
1812 | /* This line contained a key that not offered by the server */ | 1812 | /* This line contained a key that not offered by the server */ |
1813 | debug3("%s: deprecated %s key at %s:%ld", __func__, | 1813 | debug3("%s: deprecated %s key at %s:%ld", __func__, |
1814 | sshkey_ssh_name(l->key), l->path, l->linenum); | 1814 | sshkey_ssh_name(l->key), l->path, l->linenum); |
1815 | if ((tmp = reallocarray(ctx->old_keys, ctx->nold + 1, | 1815 | if ((tmp = recallocarray(ctx->old_keys, ctx->nold, ctx->nold + 1, |
1816 | sizeof(*ctx->old_keys))) == NULL) | 1816 | sizeof(*ctx->old_keys))) == NULL) |
1817 | fatal("%s: reallocarray failed nold = %zu", | 1817 | fatal("%s: recallocarray failed nold = %zu", |
1818 | __func__, ctx->nold); | 1818 | __func__, ctx->nold); |
1819 | ctx->old_keys = tmp; | 1819 | ctx->old_keys = tmp; |
1820 | ctx->old_keys[ctx->nold++] = l->key; | 1820 | ctx->old_keys[ctx->nold++] = l->key; |
@@ -2046,9 +2046,9 @@ client_input_hostkeys(void) | |||
2046 | } | 2046 | } |
2047 | } | 2047 | } |
2048 | /* Key is good, record it */ | 2048 | /* Key is good, record it */ |
2049 | if ((tmp = reallocarray(ctx->keys, ctx->nkeys + 1, | 2049 | if ((tmp = recallocarray(ctx->keys, ctx->nkeys, ctx->nkeys + 1, |
2050 | sizeof(*ctx->keys))) == NULL) | 2050 | sizeof(*ctx->keys))) == NULL) |
2051 | fatal("%s: reallocarray failed nkeys = %zu", | 2051 | fatal("%s: recallocarray failed nkeys = %zu", |
2052 | __func__, ctx->nkeys); | 2052 | __func__, ctx->nkeys); |
2053 | ctx->keys = tmp; | 2053 | ctx->keys = tmp; |
2054 | ctx->keys[ctx->nkeys++] = key; | 2054 | ctx->keys[ctx->nkeys++] = key; |
diff --git a/hostfile.c b/hostfile.c index 1804cff99..12f174ff9 100644 --- a/hostfile.c +++ b/hostfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: hostfile.c,v 1.70 2017/04/30 23:18:44 djm Exp $ */ | 1 | /* $OpenBSD: hostfile.c,v 1.71 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -251,7 +251,7 @@ record_hostkey(struct hostkey_foreach_line *l, void *_ctx) | |||
251 | l->marker == MRK_NONE ? "" : | 251 | l->marker == MRK_NONE ? "" : |
252 | (l->marker == MRK_CA ? "ca " : "revoked "), | 252 | (l->marker == MRK_CA ? "ca " : "revoked "), |
253 | sshkey_type(l->key), l->path, l->linenum); | 253 | sshkey_type(l->key), l->path, l->linenum); |
254 | if ((tmp = reallocarray(hostkeys->entries, | 254 | if ((tmp = recallocarray(hostkeys->entries, hostkeys->num_entries, |
255 | hostkeys->num_entries + 1, sizeof(*hostkeys->entries))) == NULL) | 255 | hostkeys->num_entries + 1, sizeof(*hostkeys->entries))) == NULL) |
256 | return SSH_ERR_ALLOC_FAIL; | 256 | return SSH_ERR_ALLOC_FAIL; |
257 | hostkeys->entries = tmp; | 257 | hostkeys->entries = tmp; |
@@ -14,7 +14,7 @@ | |||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* $OpenBSD: krl.c,v 1.39 2017/03/10 07:18:32 dtucker Exp $ */ | 17 | /* $OpenBSD: krl.c,v 1.40 2017/05/31 09:15:42 deraadt Exp $ */ |
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | 20 | ||
@@ -1026,7 +1026,7 @@ ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp, | |||
1026 | } | 1026 | } |
1027 | } | 1027 | } |
1028 | /* Record keys used to sign the KRL */ | 1028 | /* Record keys used to sign the KRL */ |
1029 | tmp_ca_used = reallocarray(ca_used, nca_used + 1, | 1029 | tmp_ca_used = recallocarray(ca_used, nca_used, nca_used + 1, |
1030 | sizeof(*ca_used)); | 1030 | sizeof(*ca_used)); |
1031 | if (tmp_ca_used == NULL) { | 1031 | if (tmp_ca_used == NULL) { |
1032 | r = SSH_ERR_ALLOC_FAIL; | 1032 | r = SSH_ERR_ALLOC_FAIL; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.109 2017/03/14 00:55:37 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.110 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -539,7 +539,7 @@ addargs(arglist *args, char *fmt, ...) | |||
539 | } else if (args->num+2 >= nalloc) | 539 | } else if (args->num+2 >= nalloc) |
540 | nalloc *= 2; | 540 | nalloc *= 2; |
541 | 541 | ||
542 | args->list = xreallocarray(args->list, nalloc, sizeof(char *)); | 542 | args->list = xrecallocarray(args->list, args->nalloc, nalloc, sizeof(char *)); |
543 | args->nalloc = nalloc; | 543 | args->nalloc = nalloc; |
544 | args->list[args->num++] = cp; | 544 | args->list[args->num++] = cp; |
545 | args->list[args->num] = NULL; | 545 | args->list[args->num] = NULL; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: scp.c,v 1.191 2017/05/02 08:06:33 jmc Exp $ */ | 1 | /* $OpenBSD: scp.c,v 1.192 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * scp - secure remote copy. This is basically patched BSD rcp which | 3 | * scp - secure remote copy. This is basically patched BSD rcp which |
4 | * uses ssh to do the data transfer (instead of using rcmd). | 4 | * uses ssh to do the data transfer (instead of using rcmd). |
@@ -1368,11 +1368,7 @@ allocbuf(BUF *bp, int fd, int blksize) | |||
1368 | #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */ | 1368 | #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */ |
1369 | if (bp->cnt >= size) | 1369 | if (bp->cnt >= size) |
1370 | return (bp); | 1370 | return (bp); |
1371 | if (bp->buf == NULL) | 1371 | bp->buf = xrecallocarray(bp->buf, bp->cnt, size, 1); |
1372 | bp->buf = xmalloc(size); | ||
1373 | else | ||
1374 | bp->buf = xreallocarray(bp->buf, 1, size); | ||
1375 | memset(bp->buf, 0, size); | ||
1376 | bp->cnt = size; | 1372 | bp->cnt = size; |
1377 | return (bp); | 1373 | return (bp); |
1378 | } | 1374 | } |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: session.c,v 1.287 2017/05/31 08:09:45 markus Exp $ */ | 1 | /* $OpenBSD: session.c,v 1.288 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
4 | * All rights reserved | 4 | * All rights reserved |
@@ -1711,8 +1711,8 @@ session_new(void) | |||
1711 | return NULL; | 1711 | return NULL; |
1712 | debug2("%s: allocate (allocated %d max %d)", | 1712 | debug2("%s: allocate (allocated %d max %d)", |
1713 | __func__, sessions_nalloc, options.max_sessions); | 1713 | __func__, sessions_nalloc, options.max_sessions); |
1714 | tmp = xreallocarray(sessions, sessions_nalloc + 1, | 1714 | tmp = xrecallocarray(sessions, sessions_nalloc, |
1715 | sizeof(*sessions)); | 1715 | sessions_nalloc + 1, sizeof(*sessions)); |
1716 | if (tmp == NULL) { | 1716 | if (tmp == NULL) { |
1717 | error("%s: cannot allocate %d sessions", | 1717 | error("%s: cannot allocate %d sessions", |
1718 | __func__, sessions_nalloc + 1); | 1718 | __func__, sessions_nalloc + 1); |
@@ -2036,8 +2036,8 @@ session_env_req(Session *s) | |||
2036 | for (i = 0; i < options.num_accept_env; i++) { | 2036 | for (i = 0; i < options.num_accept_env; i++) { |
2037 | if (match_pattern(name, options.accept_env[i])) { | 2037 | if (match_pattern(name, options.accept_env[i])) { |
2038 | debug2("Setting env %d: %s=%s", s->num_env, name, val); | 2038 | debug2("Setting env %d: %s=%s", s->num_env, name, val); |
2039 | s->env = xreallocarray(s->env, s->num_env + 1, | 2039 | s->env = xrecallocarray(s->env, s->num_env, |
2040 | sizeof(*s->env)); | 2040 | s->num_env + 1, sizeof(*s->env)); |
2041 | s->env[s->num_env].name = name; | 2041 | s->env[s->num_env].name = name; |
2042 | s->env[s->num_env].val = val; | 2042 | s->env[s->num_env].val = val; |
2043 | s->num_env++; | 2043 | s->num_env++; |
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c index ea97508f1..b37491c5d 100644 --- a/ssh-pkcs11.c +++ b/ssh-pkcs11.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-pkcs11.c,v 1.24 2017/05/30 14:15:17 markus Exp $ */ | 1 | /* $OpenBSD: ssh-pkcs11.c,v 1.25 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2010 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2010 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -546,8 +546,8 @@ pkcs11_fetch_keys_filter(struct pkcs11_provider *p, CK_ULONG slotidx, | |||
546 | sshkey_free(key); | 546 | sshkey_free(key); |
547 | } else { | 547 | } else { |
548 | /* expand key array and add key */ | 548 | /* expand key array and add key */ |
549 | *keysp = xreallocarray(*keysp, *nkeys + 1, | 549 | *keysp = xrecallocarray(*keysp, *nkeys, |
550 | sizeof(struct sshkey *)); | 550 | *nkeys + 1, sizeof(struct sshkey *)); |
551 | (*keysp)[*nkeys] = key; | 551 | (*keysp)[*nkeys] = key; |
552 | *nkeys = *nkeys + 1; | 552 | *nkeys = *nkeys + 1; |
553 | debug("have %d keys", *nkeys); | 553 | debug("have %d keys", *nkeys); |
@@ -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 | ||
207 | size_t | 208 | size_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 | } |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshkey.c,v 1.50 2017/05/08 06:11:06 djm Exp $ */ | 1 | /* $OpenBSD: sshkey.c,v 1.51 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2008 Alexander von Gernler. All rights reserved. | 4 | * Copyright (c) 2008 Alexander von Gernler. All rights reserved. |
@@ -1764,8 +1764,9 @@ cert_parse(struct sshbuf *b, struct sshkey *key, struct sshbuf *certbuf) | |||
1764 | goto out; | 1764 | goto out; |
1765 | } | 1765 | } |
1766 | oprincipals = key->cert->principals; | 1766 | oprincipals = key->cert->principals; |
1767 | key->cert->principals = reallocarray(key->cert->principals, | 1767 | key->cert->principals = recallocarray(key->cert->principals, |
1768 | key->cert->nprincipals + 1, sizeof(*key->cert->principals)); | 1768 | key->cert->nprincipals, key->cert->nprincipals + 1, |
1769 | sizeof(*key->cert->principals)); | ||
1769 | if (key->cert->principals == NULL) { | 1770 | if (key->cert->principals == NULL) { |
1770 | free(principal); | 1771 | free(principal); |
1771 | key->cert->principals = oprincipals; | 1772 | key->cert->principals = oprincipals; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: utf8.c,v 1.6 2017/04/17 14:31:23 schwarze Exp $ */ | 1 | /* $OpenBSD: utf8.c,v 1.7 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> | 3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> |
4 | * | 4 | * |
@@ -76,7 +76,7 @@ grow_dst(char **dst, size_t *sz, size_t maxsz, char **dp, size_t need) | |||
76 | tsz = *sz + 128; | 76 | tsz = *sz + 128; |
77 | if (tsz > maxsz) | 77 | if (tsz > maxsz) |
78 | tsz = maxsz; | 78 | tsz = maxsz; |
79 | if ((tp = realloc(*dst, tsz)) == NULL) | 79 | if ((tp = recallocarray(*dst, *sz, tsz, 1)) == NULL) |
80 | return -1; | 80 | return -1; |
81 | *dp = tp + (*dp - *dst); | 81 | *dp = tp + (*dp - *dst); |
82 | *dst = tp; | 82 | *dst = tp; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: xmalloc.c,v 1.33 2016/02/15 09:47:49 dtucker Exp $ */ | 1 | /* $OpenBSD: xmalloc.c,v 1.34 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -77,6 +77,18 @@ xreallocarray(void *ptr, size_t nmemb, size_t size) | |||
77 | return new_ptr; | 77 | return new_ptr; |
78 | } | 78 | } |
79 | 79 | ||
80 | void * | ||
81 | xrecallocarray(void *ptr, size_t onmemb, size_t nmemb, size_t size) | ||
82 | { | ||
83 | void *new_ptr; | ||
84 | |||
85 | new_ptr = recallocarray(ptr, onmemb, nmemb, size); | ||
86 | if (new_ptr == NULL) | ||
87 | fatal("xrecallocarray: out of memory (%zu elements of %zu bytes)", | ||
88 | nmemb, size); | ||
89 | return new_ptr; | ||
90 | } | ||
91 | |||
80 | char * | 92 | char * |
81 | xstrdup(const char *str) | 93 | xstrdup(const char *str) |
82 | { | 94 | { |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: xmalloc.h,v 1.16 2016/02/15 09:47:49 dtucker Exp $ */ | 1 | /* $OpenBSD: xmalloc.h,v 1.17 2017/05/31 09:15:42 deraadt Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -20,6 +20,7 @@ void ssh_malloc_init(void); | |||
20 | void *xmalloc(size_t); | 20 | void *xmalloc(size_t); |
21 | void *xcalloc(size_t, size_t); | 21 | void *xcalloc(size_t, size_t); |
22 | void *xreallocarray(void *, size_t, size_t); | 22 | void *xreallocarray(void *, size_t, size_t); |
23 | void *xrecallocarray(void *, size_t, size_t, size_t); | ||
23 | char *xstrdup(const char *); | 24 | char *xstrdup(const char *); |
24 | int xasprintf(char **, const char *, ...) | 25 | int xasprintf(char **, const char *, ...) |
25 | __attribute__((__format__ (printf, 2, 3))) | 26 | __attribute__((__format__ (printf, 2, 3))) |