summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unistd.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index b13b507..c2f5feb 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -60,6 +60,17 @@ __fortify_read(int fd, void *buf, size_t n)
60 return read(fd, buf, n); 60 return read(fd, buf, n);
61} 61}
62 62
63static inline __attribute__ ((always_inline))
64ssize_t
65__fortify_write(int fd, const void *buf, size_t n)
66{
67 size_t bos = __builtin_object_size(buf, 0);
68
69 if (n > bos)
70 __builtin_trap();
71 return write(fd, buf, n);
72}
73
63#undef confstr 74#undef confstr
64#define confstr(name, buf, len) __fortify_confstr(name, buf, len) 75#define confstr(name, buf, len) __fortify_confstr(name, buf, len)
65#undef getcwd 76#undef getcwd
@@ -70,6 +81,8 @@ __fortify_read(int fd, void *buf, size_t n)
70#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) 81#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset)
71#undef read 82#undef read
72#define read(fd, buf, n) __fortify_read(fd, buf, n) 83#define read(fd, buf, n) __fortify_read(fd, buf, n)
84#undef write
85#define write(fd, buf, n) __fortify_write(fd, buf, n)
73 86
74#endif 87#endif
75 88