fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit 958ead636c14f10fce3954712f6e70d98db952b8
parent e02237241bf01b8f4f704cf5d3054e5fcd9c20a9
Author: sin <sin@2f30.org>
Date:   Sat, 28 Feb 2015 16:48:58 +0000

Add readlink() and readlinkat() checks

Diffstat:
Minclude/unistd.h | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h @@ -96,6 +96,28 @@ __fortify_read(int fd, void *buf, size_t n) } static inline __attribute__ ((always_inline)) +ssize_t +__fortify_readlink(const char *path, char *buf, size_t n) +{ + size_t bos = __builtin_object_size(buf, 0); + + if (n > bos) + __builtin_trap(); + return readlink(path, buf, n); +} + +static inline __attribute__ ((always_inline)) +ssize_t +__fortify_readlinkat(int fd, const char *path, char *buf, size_t n) +{ + size_t bos = __builtin_object_size(buf, 0); + + if (n > bos) + __builtin_trap(); + return readlinkat(fd, path, buf, n); +} + +static inline __attribute__ ((always_inline)) int __fortify_ttyname_r(int fd, char *name, size_t n) { @@ -137,6 +159,10 @@ __fortify_write(int fd, const void *buf, size_t n) #define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) #undef read #define read(fd, buf, n) __fortify_read(fd, buf, n) +#undef readlink +#define readlink(path, buf, n) __fortify_readlink(path, buf, n) +#undef readlinkat +#define readlinkat(fd, path, buf, n) __fortify_readlinkat(fd, path, buf, n) #undef ttyname_r #define ttyname_r(fd, name, n) __fortify_ttyname_r(fd, name, n) #undef write