From d8afaf63d24933f6e1706c4019155b8e09fe9d32 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 24 Feb 2015 19:37:25 +0000 Subject: Add send() check --- include/sys/socket.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/sys/socket.h b/include/sys/socket.h index 85ba63b..4dc228e 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -27,10 +27,23 @@ __fortify_recvfrom(int sockfd, void *buf, size_t n, int flags, struct sockaddr * return recvfrom(sockfd, buf, n, flags, sa, salen); } +static inline __attribute__ ((always_inline)) +ssize_t +__fortify_send(int sockfd, const void *buf, size_t n, int flags) +{ + size_t bos = __builtin_object_size(buf, 0); + + if (n > bos) + __builtin_trap(); + return send(sockfd, buf, n, flags); +} + #undef recv #define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags) #undef recvfrom #define recvfrom(sockfd, buf, n, flags, sa, salen) __fortify_recvfrom(sockfd, buf, n, flags, sa, salen) +#undef send +#define send(sockfd, buf, n, flags) __fortify_send(sockfd, buf, n, flags) #endif -- cgit v1.3