X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Freadwrite.c;h=a862d1cffd1f9e195ed294e13f1a3438dbf094f4;hb=345e47a1c109b0192e3822c6a3d28b3880730157;hp=7b8460962eda5ee7e917be20cce7c47be0a56ea4;hpb=043af8b55bfcc8276b7ae301efa2c72b1f3378e3;p=lttng-tools.git diff --git a/src/common/readwrite.c b/src/common/readwrite.c index 7b8460962..a862d1cff 100644 --- a/src/common/readwrite.c +++ b/src/common/readwrite.c @@ -15,8 +15,11 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _GNU_SOURCE +#define _LGPL_SOURCE #include #include +#include #include #include "readwrite.h" @@ -36,6 +39,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 +76,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) {