summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2016-07-11 23:34:18 +0800
committerMatt Johnston <matt@ucc.asn.au>2016-07-11 23:34:18 +0800
commitc0f63ee1003c06b775e273478d82897aedec0ce4 (patch)
tree8783c4a833d913f0f5f531096d2e1aab6b50ad5d /buffer.c
parent8fd720c3e319da773b48c0b191f049dbd1e3c7f0 (diff)
downloaddropbear-c0f63ee1003c06b775e273478d82897aedec0ce4.tar.gz
additional length checks
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/buffer.c b/buffer.c
index cd974e3..d646c0e 100644
--- a/buffer.c
+++ b/buffer.c
@@ -141,9 +141,10 @@ void buf_incrwritepos(buffer* buf, unsigned int incr) {
/* increment the position by incr, negative values are allowed, to
* decrement the pos*/
void buf_incrpos(buffer* buf, int incr) {
- if (incr > BUF_MAX_INCR ||
- (unsigned int)((int)buf->pos + incr) > buf->len
- || ((int)buf->pos + incr) < 0) {
+ if (incr > BUF_MAX_INCR
+ || incr < -BUF_MAX_INCR
+ || (unsigned int)((int)buf->pos + incr) > buf->len
+ || ((int)buf->pos + incr) < 0) {
dropbear_exit("Bad buf_incrpos");
}
buf->pos += incr;
@@ -184,7 +185,7 @@ void buf_putbyte(buffer* buf, unsigned char val) {
* the next len bytes from that position can be used */
unsigned char* buf_getptr(buffer* buf, unsigned int len) {
- if (buf->pos + len > buf->len) {
+ if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
dropbear_exit("Bad buf_getptr");
}
return &buf->data[buf->pos];
@@ -194,7 +195,7 @@ unsigned char* buf_getptr(buffer* buf, unsigned int len) {
* This allows writing past the used length, but not past the size */
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) {
- if (buf->pos + len > buf->size) {
+ if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
dropbear_exit("Bad buf_getwriteptr");
}
return &buf->data[buf->pos];