diff options
author | 2019-01-21 09:54:11 +0000 | |
---|---|---|
committer | 2019-01-21 09:54:11 +0000 | |
commit | f37f3ee23e78db3061951f8cc15291bbef4b09cf (patch) | |
tree | 174db40b7acff1092f402685d6208400049486f9 /usr.bin/ssh/sshbuf-getput-crypto.c | |
parent | remove obsolete (SSH v.1) sshbuf_get/put_bignum1 functions (diff) | |
download | wireguard-openbsd-f37f3ee23e78db3061951f8cc15291bbef4b09cf.tar.xz wireguard-openbsd-f37f3ee23e78db3061951f8cc15291bbef4b09cf.zip |
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@
Diffstat (limited to 'usr.bin/ssh/sshbuf-getput-crypto.c')
-rw-r--r-- | usr.bin/ssh/sshbuf-getput-crypto.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/usr.bin/ssh/sshbuf-getput-crypto.c b/usr.bin/ssh/sshbuf-getput-crypto.c index 9d0da3b935e..fa91a8abd26 100644 --- a/usr.bin/ssh/sshbuf-getput-crypto.c +++ b/usr.bin/ssh/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 * @@ -28,16 +28,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; } |