From fbf02d5936c5a424b4c6d6b5d7328c78dcc75a76 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Sun, 20 Aug 2023 21:23:32 +0200 Subject: [PATCH] buffer.c: Support 'F' for padded bignums Signed-off-by: Simon Josefsson Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider Reviewed-by: Sahana Prasad --- src/buffer.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index d56149cb..579151c9 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -872,13 +872,20 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer, va_arg(ap, void *); count++; /* increase argument count */ break; + case 'F': case 'B': va_arg(ap, bignum); /* * Use a fixed size for a bignum * (they should normally be around 32) */ - needed_size += 64; + if (*p == 'F') { + len = va_arg(ap, size_t); + count++; /* increase argument count */ + needed_size += sizeof(uint32_t) + len; + } else { + needed_size += 64; + } break; case 't': cstring = va_arg(ap, char *); @@ -1008,9 +1015,16 @@ ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, rc = ssh_buffer_add_data(buffer, o.data, (uint32_t)len); o.data = NULL; break; + case 'F': case 'B': b = va_arg(ap, bignum); - o.string = ssh_make_bignum_string(b); + if (*p == 'F') { + len = va_arg(ap, size_t); + count++; /* increase argument count */ + o.string = ssh_make_padded_bignum_string(b, len); + } else { + o.string = ssh_make_bignum_string(b); + } if(o.string == NULL){ rc = SSH_ERROR; break; @@ -1066,6 +1080,8 @@ ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, * 'P': size_t, void * (len of data, pointer to data) * only pushes data. * 'B': bignum (pushed as SSH string) + * 'F': bignum, size_t (bignum, padded to fixed length, + * pushed 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