summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-22 20:45:52 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-22 20:45:52 +0200
commit349440892725cc5aefd7839bc4d30611c0092898 (patch)
tree25e9080b0eaff23f6c7de907370972c96464f66f
parentbe5eb1da462a2d715172a98aa236d4d88dbd557c (diff)
kern/cbuf: fix very unlikely but potential integer overflows
-rw-r--r--kern/cbuf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kern/cbuf.c b/kern/cbuf.c
index f00532ef..ea848c56 100644
--- a/kern/cbuf.c
+++ b/kern/cbuf.c
@@ -99,7 +99,7 @@ cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size)
end = start + size;
buf_end = cbuf->buf + cbuf->capacity;
- if (end > buf_end) {
+ if ((end <= cbuf->buf) || (end > buf_end)) {
skip = buf_end - start;
memcpy(start, buf, skip);
buf += skip;
@@ -133,7 +133,7 @@ cbuf_read(const struct cbuf *cbuf, size_t index, void *buf, size_t *sizep)
end = start + *sizep;
buf_end = cbuf->buf + cbuf->capacity;
- if (end <= buf_end) {
+ if ((end > cbuf->buf) && (end <= buf_end)) {
size = *sizep;
} else {
size = buf_end - start;