aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2017-04-13 16:19:28 +0200
committerAndreas Schneider <asn@cryptomilk.org>2017-04-13 16:19:28 +0200
commitf21ddefedb1230536b67a80efaf333664a38b54c (patch)
tree3db63c63fef4b10f9884eb3a929e7f900dbcb885
parent0cf1c8554296d999dec20d0175eb28d87433dbca (diff)
downloadlibssh-f21ddefedb1230536b67a80efaf333664a38b54c.tar.gz
libssh-f21ddefedb1230536b67a80efaf333664a38b54c.tar.xz
libssh-f21ddefedb1230536b67a80efaf333664a38b54c.zip
Revert "buffer: Create ssh_buffer_validate_length()"
This reverts commit 34bdc1ca7871e8e9258077411edd516c8de55299.
-rw-r--r--include/libssh/buffer.h2
-rw-r--r--src/buffer.c24
2 files changed, 3 insertions, 23 deletions
diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 81d9452b..d4cb071b 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -48,8 +48,6 @@ int ssh_buffer_add_u16(ssh_buffer buffer, uint16_t data);
int ssh_buffer_add_u32(ssh_buffer buffer, uint32_t data);
int ssh_buffer_add_u64(ssh_buffer buffer, uint64_t data);
-int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len);
-
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
const char *format,
int argc,
diff --git a/src/buffer.c b/src/buffer.c
index 0c776698..61b07e9a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -526,8 +526,8 @@ uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint3
* Check for a integer overflow first, then check if not enough data is in
* the buffer.
*/
- if (!ssh_buffer_validate_length(buffer, len)) {
- return 0;
+ if (buffer->pos + len < len || buffer->pos + len > buffer->used) {
+ return 0;
}
memcpy(data,buffer->data+buffer->pos,len);
buffer->pos+=len;
@@ -581,24 +581,6 @@ int ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
}
/**
- * @brief Valdiates that the given length can be obtained from the buffer.
- *
- * @param[in] buffer The buffer to read from.
- *
- * @param[in] len The length to be checked.
- *
- * @return SSH_OK if the length is valid, SSH_ERROR otherwise.
- */
-int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len)
-{
- if (buffer->pos + len < len || buffer->pos + len > buffer->used) {
- return SSH_ERROR;
- }
-
- return SSH_OK;
-}
-
-/**
* @internal
*
* @brief Get a SSH String out of the buffer and adjusts the read pointer.
@@ -617,7 +599,7 @@ struct ssh_string_struct *ssh_buffer_get_ssh_string(struct ssh_buffer_struct *bu
}
hostlen = ntohl(stringlen);
/* verify if there is enough space in buffer to get it */
- if (!ssh_buffer_validate_length(buffer, hostlen) {
+ if (buffer->pos + hostlen < hostlen || buffer->pos + hostlen > buffer->used) {
return NULL; /* it is indeed */
}
str = ssh_string_new(hostlen);