mirror of
https://github.com/libssh2/libssh2.git
synced 2025-09-01 06:21:57 +03:00
Simplified _libssh2_check_length (#350)
* Simplified _libssh2_check_length misc.c : _libssh2_check_length() Removed cast and improved bounds checking and format. Credit : Yuriy M. Kaminskiy
This commit is contained in:
@@ -811,10 +811,9 @@ int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf)
|
|||||||
|
|
||||||
int _libssh2_check_length(struct string_buf *buf, size_t len)
|
int _libssh2_check_length(struct string_buf *buf, size_t len)
|
||||||
{
|
{
|
||||||
if(len > buf->len)
|
unsigned char *endp = &buf->data[buf->len];
|
||||||
return 0;
|
size_t left = endp - buf->dataptr;
|
||||||
|
return ((len <= left) && (left <= buf->len));
|
||||||
return ((int)(buf->dataptr - buf->data) <= (int)(buf->len - len)) ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrappers */
|
/* Wrappers */
|
||||||
|
Reference in New Issue
Block a user