2015-03-11 18:55:51 +00:00
|
|
|
#ifndef _FORTIFY_SYS_SOCKET_H
|
|
|
|
#define _FORTIFY_SYS_SOCKET_H
|
2015-01-30 16:43:36 +00:00
|
|
|
|
|
|
|
#include_next <sys/socket.h>
|
|
|
|
|
|
|
|
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
|
|
|
|
2015-03-11 11:18:31 +00:00
|
|
|
#ifndef __cplusplus
|
2015-03-11 09:26:11 +00:00
|
|
|
|
2015-01-30 16:43:36 +00:00
|
|
|
static inline __attribute__ ((always_inline))
|
|
|
|
ssize_t
|
|
|
|
__fortify_recv(int sockfd, void *buf, size_t n, int flags)
|
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
|
|
|
return recv(sockfd, buf, n, flags);
|
|
|
|
}
|
|
|
|
|
2015-02-04 14:58:32 +00:00
|
|
|
static inline __attribute__ ((always_inline))
|
|
|
|
ssize_t
|
2015-02-28 16:56:21 +00:00
|
|
|
__fortify_recvfrom(int sockfd, void *buf, size_t n, int flags,
|
|
|
|
struct sockaddr *sa, socklen_t *salen)
|
2015-02-04 14:58:32 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
|
|
|
return recvfrom(sockfd, buf, n, flags, sa, salen);
|
|
|
|
}
|
|
|
|
|
2015-02-24 19:37:25 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-02-28 16:56:21 +00:00
|
|
|
static inline __attribute__ ((always_inline))
|
|
|
|
ssize_t
|
|
|
|
__fortify_sendto(int sockfd, const void *buf, size_t n, int flags,
|
|
|
|
const struct sockaddr *sa, socklen_t salen)
|
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
|
|
|
return sendto(sockfd, buf, n, flags, sa, salen);
|
|
|
|
}
|
|
|
|
|
2015-01-30 16:43:36 +00:00
|
|
|
#undef recv
|
|
|
|
#define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags)
|
2015-02-04 14:58:32 +00:00
|
|
|
#undef recvfrom
|
|
|
|
#define recvfrom(sockfd, buf, n, flags, sa, salen) __fortify_recvfrom(sockfd, buf, n, flags, sa, salen)
|
2015-02-24 19:37:25 +00:00
|
|
|
#undef send
|
|
|
|
#define send(sockfd, buf, n, flags) __fortify_send(sockfd, buf, n, flags)
|
2015-02-28 16:56:21 +00:00
|
|
|
#undef sendto
|
|
|
|
#define sendto(sockfd, buf, n, flags, sa, salen) __fortify_sendto(sockfd, buf, n, flags, sa, salen)
|
2015-01-30 16:43:36 +00:00
|
|
|
|
2015-03-11 09:26:11 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-30 16:43:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|