commit d8afaf63d24933f6e1706c4019155b8e09fe9d32
parent eb7c60712c85bfea0f4265219d1f457d144984ff
Author: sin <sin@2f30.org>
Date: Tue, 24 Feb 2015 19:37:25 +0000
Add send() check
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git 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