buffer: Calculate correctly the bignum size in buffer

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
Jakub Jelen
2025-01-03 15:39:07 +01:00
parent 4becc8eb82
commit dab51d8e20

View File

@@ -828,6 +828,7 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
const char *p = NULL; const char *p = NULL;
ssh_string string = NULL; ssh_string string = NULL;
char *cstring = NULL; char *cstring = NULL;
bignum b = NULL;
size_t needed_size = 0; size_t needed_size = 0;
size_t len; size_t len;
size_t count; size_t count;
@@ -874,17 +875,15 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
break; break;
case 'F': case 'F':
case 'B': case 'B':
va_arg(ap, bignum); b = va_arg(ap, bignum);
/*
* Use a fixed size for a bignum
* (they should normally be around 32)
*/
if (*p == 'F') { if (*p == 'F') {
/* For padded bignum, we know the exact length */
len = va_arg(ap, size_t); len = va_arg(ap, size_t);
count++; /* increase argument count */ count++; /* increase argument count */
needed_size += sizeof(uint32_t) + len; needed_size += sizeof(uint32_t) + len;
} else { } else {
needed_size += 64; /* The bignum bytes + 1 for possible padding */
needed_size += sizeof(uint32_t) + bignum_num_bytes(b) + 1;
} }
break; break;
case 't': case 't':