1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

buffer: Support bignums in ssh_buffer_unpack()

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Aris Adamantiadis
2016-01-01 21:51:15 +01:00
committed by Andreas Schneider
parent 2f8239ade3
commit a6c47099b7

View File

@@ -1094,9 +1094,11 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
uint64_t *qword; uint64_t *qword;
ssh_string *string; ssh_string *string;
char **cstring; char **cstring;
bignum *bignum;
void **data; void **data;
} o; } o;
size_t len, rlen, max_len; size_t len, rlen, max_len;
ssh_string tmp_string = NULL;
va_list ap_copy; va_list ap_copy;
int count; /* int for size comparison with argc */ 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); *o.qword = ntohll(*o.qword);
rc = rlen==8 ? SSH_OK : SSH_ERROR; rc = rlen==8 ? SSH_OK : SSH_ERROR;
break; 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': case 'S':
o.string = va_arg(ap, ssh_string *); o.string = va_arg(ap, ssh_string *);
*o.string = ssh_buffer_get_ssh_string(buffer); *o.string = ssh_buffer_get_ssh_string(buffer);
@@ -1267,6 +1282,10 @@ cleanup:
break; break;
} }
break; break;
case 'B':
o.bignum = va_arg(ap_copy, bignum *);
bignum_safe_free(*o.bignum);
break;
case 'S': case 'S':
o.string = va_arg(ap_copy, ssh_string *); o.string = va_arg(ap_copy, ssh_string *);
if (buffer->secure) { if (buffer->secure) {
@@ -1313,6 +1332,7 @@ cleanup:
* 's': char ** (C string, pulled as SSH string) * 's': char ** (C string, pulled as SSH string)
* 'P': size_t, void ** (len of data, pointer to data) * 'P': size_t, void ** (len of data, pointer to data)
* only pulls data. * only pulls data.
* 'B': bignum * (pulled as SSH string)
* @returns SSH_OK on success * @returns SSH_OK on success
* SSH_ERROR on error * SSH_ERROR on error
* @warning when using 'P' with a constant size (e.g. 8), do not * @warning when using 'P' with a constant size (e.g. 8), do not