diff options
| author | sin | 2015-01-30 16:43:36 +0000 |
|---|---|---|
| committer | sin | 2015-01-30 16:43:36 +0000 |
| commit | aa095b6d52ca4fa3b053d15c871c6ece34f99d1c (patch) | |
| tree | 8872be08cd9669fc20528c969cf90044735717a5 /include | |
| parent | 6f0d1a1b6f4b449bb0b59545f2b66d61a1c1b4f3 (diff) | |
Add recv() checks
Diffstat (limited to 'include')
| -rw-r--r-- | include/sys/socket.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/sys/socket.h b/include/sys/socket.h new file mode 100644 index 0000000..df15961 --- /dev/null +++ b/include/sys/socket.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | ||
| 2 | #ifndef FORTIFY_SYS_SOCKET_H_ | ||
| 3 | #define FORTIFY_SYS_SOCKET_H_ | ||
| 4 | |||
| 5 | #include_next <sys/socket.h> | ||
| 6 | |||
| 7 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 8 | |||
| 9 | #define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg))) | ||
| 10 | |||
| 11 | __errordecl(__recv_error, "recv: buffer overflow detected"); | ||
| 12 | static inline __attribute__ ((always_inline)) | ||
| 13 | ssize_t | ||
| 14 | __fortify_recv(int sockfd, void *buf, size_t n, int flags) | ||
| 15 | { | ||
| 16 | size_t bos = __builtin_object_size(buf, 0); | ||
| 17 | |||
| 18 | if (__builtin_constant_p(n) && n > bos) | ||
| 19 | __recv_error(); | ||
| 20 | |||
| 21 | if (n > bos) | ||
| 22 | __builtin_trap(); | ||
| 23 | return recv(sockfd, buf, n, flags); | ||
| 24 | } | ||
| 25 | |||
| 26 | #undef recv | ||
| 27 | #define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags) | ||
| 28 | |||
| 29 | #endif | ||
| 30 | |||
| 31 | #endif | ||
