From a6c47099b7f042180bb712030519c116599352e4 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Fri, 1 Jan 2016 21:51:15 +0100 Subject: [PATCH] buffer: Support bignums in ssh_buffer_unpack() Signed-off-by: Aris Adamantiadis Reviewed-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/buffer.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/buffer.c b/src/buffer.c index 99863747..62b6b47c 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1094,9 +1094,11 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer, uint64_t *qword; ssh_string *string; char **cstring; + bignum *bignum; void **data; } o; size_t len, rlen, max_len; + ssh_string tmp_string = NULL; va_list ap_copy; int count; /* int for size comparison with argc */ @@ -1136,6 +1138,19 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer, *o.qword = ntohll(*o.qword); rc = rlen==8 ? SSH_OK : SSH_ERROR; break; + case 'B': + o.bignum = va_arg(ap, bignum *); + *o.bignum = NULL; + tmp_string = ssh_buffer_get_ssh_string(buffer); + if (tmp_string == NULL) { + rc = SSH_ERROR; + break; + } + *o.bignum = ssh_make_string_bn(tmp_string); + ssh_string_burn(tmp_string); + SSH_STRING_FREE(tmp_string); + rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR; + break; case 'S': o.string = va_arg(ap, ssh_string *); *o.string = ssh_buffer_get_ssh_string(buffer); @@ -1267,6 +1282,10 @@ cleanup: break; } break; + case 'B': + o.bignum = va_arg(ap_copy, bignum *); + bignum_safe_free(*o.bignum); + break; case 'S': o.string = va_arg(ap_copy, ssh_string *); if (buffer->secure) { @@ -1313,6 +1332,7 @@ cleanup: * 's': char ** (C string, pulled as SSH string) * 'P': size_t, void ** (len of data, pointer to data) * only pulls data. + * 'B': bignum * (pulled as SSH string) * @returns SSH_OK on success * SSH_ERROR on error * @warning when using 'P' with a constant size (e.g. 8), do not