diff options
author | deraadt@openbsd.org <deraadt@openbsd.org> | 2017-05-31 09:15:42 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2017-06-01 14:55:22 +1000 |
commit | 9e509d4ec97cb3d71696f1a2f1fdad254cbbce11 (patch) | |
tree | 8f33ae8fa9bcfa0d9c80d0e0f1555a814a844bc1 /sshkey.c | |
parent | dc5dc45662773c0f7745c29cf77ae2d52723e55e (diff) |
upstream commit
Switch to recallocarray() for a few operations. Both
growth and shrinkage are handled safely, and there also is no need for
preallocation dances. Future changes in this area will be less error prone.
Review and one bug found by markus
Upstream-ID: 822d664d6a5a1d10eccb23acdd53578a679d5065
Diffstat (limited to 'sshkey.c')
-rw-r--r-- | sshkey.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |