Fix: in lttng_read/write deny count bigger than the possible returned value
authorDavid Goulet <dgoulet@efficios.com>
Mon, 10 Feb 2014 18:43:08 +0000 (13:43 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 11 Feb 2014 19:58:46 +0000 (14:58 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/readwrite.c

index 7b8460962eda5ee7e917be20cce7c47be0a56ea4..d33e0519088049bdb4895198d167d872522d9671 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <limits.h>
 #include <unistd.h>
 
 #include "readwrite.h"
@@ -36,6 +37,14 @@ ssize_t lttng_read(int fd, void *buf, size_t count)
 
        assert(buf);
 
+       /*
+        * Deny a read count that can be bigger then the returned value max size.
+        * This makes the function to never return an overflow value.
+        */
+       if (count > SSIZE_MAX) {
+               return -EINVAL;
+       }
+
        do {
                ret = read(fd, buf + i, count - i);
                if (ret < 0) {
@@ -65,6 +74,14 @@ ssize_t lttng_write(int fd, const void *buf, size_t count)
 
        assert(buf);
 
+       /*
+        * Deny a write count that can be bigger then the returned value max size.
+        * This makes the function to never return an overflow value.
+        */
+       if (count > SSIZE_MAX) {
+               return -EINVAL;
+       }
+
        do {
                ret = write(fd, buf + i, count - i);
                if (ret < 0) {
This page took 0.027262 seconds and 4 git commands to generate.