summaryrefslogtreecommitdiffstats
path: root/sshbuf-getput-crypto.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-21 10:54:11 +0100
committerDamien Miller <djm@mindrot.org>2019-01-21 11:47:28 +0100
commit7be8572b32a15d5c3dba897f252e2e04e991c307 (patch)
tree449782dce059d2eb8d28aaa3baeaedd876b915a2 /sshbuf-getput-crypto.c
parentupstream: remove obsolete (SSH v.1) sshbuf_get/put_bignum1 (diff)
downloadopenssh-7be8572b32a15d5c3dba897f252e2e04e991c307.tar.xz
openssh-7be8572b32a15d5c3dba897f252e2e04e991c307.zip
upstream: Make sshpkt_get_bignum2() allocate the bignum it is
parsing rather than make the caller do it. Saves a lot of boilerplate code. from markus@ ok djm@ OpenBSD-Commit-ID: 576bf784f9a240f5a1401f7005364e59aed3bce9
Diffstat (limited to 'sshbuf-getput-crypto.c')
-rw-r--r--sshbuf-getput-crypto.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sshbuf-getput-crypto.c b/sshbuf-getput-crypto.c
index a49b72ef7..3dd1e1446 100644
--- a/sshbuf-getput-crypto.c
+++ b/sshbuf-getput-crypto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshbuf-getput-crypto.c,v 1.6 2019/01/21 09:52:25 djm Exp $ */
+/* $OpenBSD: sshbuf-getput-crypto.c,v 1.7 2019/01/21 09:54:11 djm Exp $ */
/*
* Copyright (c) 2011 Damien Miller
*
@@ -32,16 +32,25 @@
#include "sshbuf.h"
int
-sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM *v)
+sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM **valp)
{
+ BIGNUM *v;
const u_char *d;
size_t len;
int r;
+ if (valp != NULL)
+ *valp = NULL;
if ((r = sshbuf_get_bignum2_bytes_direct(buf, &d, &len)) != 0)
return r;
- if (v != NULL && BN_bin2bn(d, len, v) == NULL)
- return SSH_ERR_ALLOC_FAIL;
+ if (valp != NULL) {
+ if ((v = BN_new()) == NULL ||
+ BN_bin2bn(d, len, v) == NULL) {
+ BN_clear_free(v);
+ return SSH_ERR_ALLOC_FAIL;
+ }
+ *valp = v;
+ }
return 0;
}