summaryrefslogtreecommitdiff
path: root/include/sys/socket.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/sys/socket.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/sys/socket.h b/include/sys/socket.h
index df15961..824cb4e 100644
--- 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)
23 return recv(sockfd, buf, n, flags); 23 return recv(sockfd, buf, n, flags);
24} 24}
25 25
26__errordecl(__recvfrom_error, "recvfrom: buffer overflow detected");
27static inline __attribute__ ((always_inline))
28ssize_t
29__fortify_recvfrom(int sockfd, void *buf, size_t n, int flags, struct sockaddr *sa, socklen_t *salen)
30{
31 size_t bos = __builtin_object_size(buf, 0);
32
33 if (__builtin_constant_p(n) && n > bos)
34 __recvfrom_error();
35
36 if (n > bos)
37 __builtin_trap();
38 return recvfrom(sockfd, buf, n, flags, sa, salen);
39}
40
26#undef recv 41#undef recv
27#define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags) 42#define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags)
43#undef recvfrom
44#define recvfrom(sockfd, buf, n, flags, sa, salen) __fortify_recvfrom(sockfd, buf, n, flags, sa, salen)
28 45
29#endif 46#endif
30 47