diff options
Diffstat (limited to 'sshbuf-getput-crypto.c')
-rw-r--r-- | sshbuf-getput-crypto.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/sshbuf-getput-crypto.c b/sshbuf-getput-crypto.c index 74351d3e5..e2e093c00 100644 --- a/sshbuf-getput-crypto.c +++ b/sshbuf-getput-crypto.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshbuf-getput-crypto.c,v 1.2 2014/06/18 15:42:09 naddy Exp $ */ | 1 | /* $OpenBSD: sshbuf-getput-crypto.c,v 1.4 2015/01/14 15:02:39 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller | 3 | * Copyright (c) 2011 Damien Miller |
4 | * | 4 | * |
@@ -38,24 +38,10 @@ sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM *v) | |||
38 | size_t len; | 38 | size_t len; |
39 | int r; | 39 | int r; |
40 | 40 | ||
41 | if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0) | 41 | if ((r = sshbuf_get_bignum2_bytes_direct(buf, &d, &len)) != 0) |
42 | return r; | 42 | return r; |
43 | /* Refuse negative (MSB set) bignums */ | ||
44 | if ((len != 0 && (*d & 0x80) != 0)) | ||
45 | return SSH_ERR_BIGNUM_IS_NEGATIVE; | ||
46 | /* Refuse overlong bignums, allow prepended \0 to avoid MSB set */ | ||
47 | if (len > SSHBUF_MAX_BIGNUM + 1 || | ||
48 | (len == SSHBUF_MAX_BIGNUM + 1 && *d != 0)) | ||
49 | return SSH_ERR_BIGNUM_TOO_LARGE; | ||
50 | if (v != NULL && BN_bin2bn(d, len, v) == NULL) | 43 | if (v != NULL && BN_bin2bn(d, len, v) == NULL) |
51 | return SSH_ERR_ALLOC_FAIL; | 44 | return SSH_ERR_ALLOC_FAIL; |
52 | /* Consume the string */ | ||
53 | if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) { | ||
54 | /* Shouldn't happen */ | ||
55 | SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR")); | ||
56 | SSHBUF_ABORT(); | ||
57 | return SSH_ERR_INTERNAL_ERROR; | ||
58 | } | ||
59 | return 0; | 45 | return 0; |
60 | } | 46 | } |
61 | 47 | ||
@@ -195,7 +181,8 @@ sshbuf_put_bignum1(struct sshbuf *buf, const BIGNUM *v) | |||
195 | return r; | 181 | return r; |
196 | } | 182 | } |
197 | POKE_U16(dp, len_bits); | 183 | POKE_U16(dp, len_bits); |
198 | memcpy(dp + 2, d, len_bytes); | 184 | if (len_bytes != 0) |
185 | memcpy(dp + 2, d, len_bytes); | ||
199 | bzero(d, sizeof(d)); | 186 | bzero(d, sizeof(d)); |
200 | return 0; | 187 | return 0; |
201 | } | 188 | } |