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

buffer: Use size_t for argc argument in ssh_buffer_(un)pack()

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2018-12-07 12:06:03 +01:00
parent 21e2522360
commit c306a693f3
2 changed files with 21 additions and 21 deletions

View File

@@ -40,11 +40,11 @@ void *ssh_buffer_allocate(struct ssh_buffer_struct *buffer, uint32_t len);
int ssh_buffer_allocate_size(struct ssh_buffer_struct *buffer, uint32_t len); int ssh_buffer_allocate_size(struct ssh_buffer_struct *buffer, uint32_t len);
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
const char *format, const char *format,
int argc, size_t argc,
va_list ap); va_list ap);
int _ssh_buffer_pack(struct ssh_buffer_struct *buffer, int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
const char *format, const char *format,
int argc, size_t argc,
...); ...);
#define ssh_buffer_pack(buffer, format, ...) \ #define ssh_buffer_pack(buffer, format, ...) \
_ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END) _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)

View File

@@ -809,7 +809,7 @@ ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer)
*/ */
static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer, static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
const char *format, const char *format,
int argc, size_t argc,
va_list ap) va_list ap)
{ {
const char *p = NULL; const char *p = NULL;
@@ -817,12 +817,12 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
char *cstring = NULL; char *cstring = NULL;
size_t needed_size = 0; size_t needed_size = 0;
size_t len; size_t len;
int count; /* int for size comparison with argc */ size_t count;
int rc = SSH_OK; int rc = SSH_OK;
for (p = format, count = 0; *p != '\0'; p++, count++) { for (p = format, count = 0; *p != '\0'; p++, count++) {
/* Invalid number of arguments passed */ /* Invalid number of arguments passed */
if (argc != -1 && count > argc) { if (count > argc) {
return SSH_ERROR; return SSH_ERROR;
} }
@@ -881,7 +881,7 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
} }
} }
if (argc != -1 && argc != count) { if (argc != count) {
return SSH_ERROR; return SSH_ERROR;
} }
@@ -891,13 +891,9 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
*/ */
uint32_t canary = va_arg(ap, uint32_t); uint32_t canary = va_arg(ap, uint32_t);
if (canary != SSH_BUFFER_PACK_END) { if (canary != SSH_BUFFER_PACK_END) {
if (argc == -1){
return SSH_ERROR;
} else {
abort(); abort();
} }
} }
}
rc = ssh_buffer_allocate_size(buffer, needed_size); rc = ssh_buffer_allocate_size(buffer, needed_size);
if (rc != 0) { if (rc != 0) {
@@ -918,7 +914,7 @@ static int ssh_buffer_pack_allocate_va(struct ssh_buffer_struct *buffer,
*/ */
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
const char *format, const char *format,
int argc, size_t argc,
va_list ap) va_list ap)
{ {
int rc = SSH_ERROR; int rc = SSH_ERROR;
@@ -934,11 +930,15 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
char *cstring; char *cstring;
bignum b; bignum b;
size_t len; size_t len;
int count; /* int for size comparison with argc */ size_t count;
if (argc > 256) {
return SSH_ERROR;
}
for (p = format, count = 0; *p != '\0'; p++, count++) { for (p = format, count = 0; *p != '\0'; p++, count++) {
/* Invalid number of arguments passed */ /* Invalid number of arguments passed */
if (argc != -1 && count > argc) { if (count > argc) {
return SSH_ERROR; return SSH_ERROR;
} }
@@ -1010,7 +1010,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
} }
} }
if (argc != -1 && argc != count) { if (argc != count) {
return SSH_ERROR; return SSH_ERROR;
} }
@@ -1018,13 +1018,9 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
/* Check if our canary is intact, if not somthing really bad happened */ /* Check if our canary is intact, if not somthing really bad happened */
uint32_t canary = va_arg(ap, uint32_t); uint32_t canary = va_arg(ap, uint32_t);
if (canary != SSH_BUFFER_PACK_END) { if (canary != SSH_BUFFER_PACK_END) {
if (argc == -1){
return SSH_ERROR;
} else {
abort(); abort();
} }
} }
}
return rc; return rc;
} }
@@ -1050,12 +1046,16 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
*/ */
int _ssh_buffer_pack(struct ssh_buffer_struct *buffer, int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
const char *format, const char *format,
int argc, size_t argc,
...) ...)
{ {
va_list ap; va_list ap;
int rc; int rc;
if (argc > 256) {
return SSH_ERROR;
}
va_start(ap, argc); va_start(ap, argc);
rc = ssh_buffer_pack_allocate_va(buffer, format, argc, ap); rc = ssh_buffer_pack_allocate_va(buffer, format, argc, ap);
va_end(ap); va_end(ap);