fortify-headers

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

commit 91c0c1270f5f690d787a126fe20430ec6409eb9f
parent cc262554a1078e572813e55ad031e146c33c8573
Author: sin <sin@2f30.org>
Date:   Wed Feb  4 14:58:32 +0000

Add recvfrom() checks

Diffstat:
include/sys/socket.h | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/include/sys/socket.h b/include/sys/socket.h @@ -23,8 +23,25 @@ __fortify_recv(int sockfd, void *buf, size_t n, int flags) return recv(sockfd, buf, n, flags); } +__errordecl(__recvfrom_error, "recvfrom: buffer overflow detected"); +static inline __attribute__ ((always_inline)) +ssize_t +__fortify_recvfrom(int sockfd, void *buf, size_t n, int flags, struct sockaddr *sa, socklen_t *salen) +{ + size_t bos = __builtin_object_size(buf, 0); + + if (__builtin_constant_p(n) && n > bos) + __recvfrom_error(); + + if (n > bos) + __builtin_trap(); + return recvfrom(sockfd, buf, n, flags, sa, salen); +} + #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) #endif