From: David Goulet Date: Mon, 10 Feb 2014 18:43:08 +0000 (-0500) Subject: Fix: in lttng_read/write deny count bigger than the possible returned value X-Git-Tag: v2.5.0-rc1~195 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=636ae5db984a5e01e2c148b5bea5306f84258f8e;p=lttng-tools.git Fix: in lttng_read/write deny count bigger than the possible returned value Signed-off-by: David Goulet --- diff --git a/src/common/readwrite.c b/src/common/readwrite.c index 7b8460962..d33e05190 100644 --- a/src/common/readwrite.c +++ b/src/common/readwrite.c @@ -17,6 +17,7 @@ #include #include +#include #include #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) {