summaryrefslogtreecommitdiff
path: root/include/sys/socket.h
blob: 5db1cb1ea4a6322b4c009c175207d7a23d81bda3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _FORTIFY_SYS_SOCKET_H
#define _FORTIFY_SYS_SOCKET_H

#include_next <sys/socket.h>

#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
#include "../fortify-headers.h"

#ifdef __cplusplus
extern "C" {
#endif

#undef recv
#undef recvfrom
#undef send
#undef sendto

fortify_fn(recv) ssize_t recv(int sockfd, void *buf, size_t n, int flags)
{
	size_t bos = __builtin_object_size(buf, 0);

	if (n > bos)
		__builtin_trap();
	return __orig_recv(sockfd, buf, n, flags);
}

fortify_fn(recvfrom) ssize_t 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 (n > bos)
		__builtin_trap();
	return __orig_recvfrom(sockfd, buf, n, flags, sa, salen);
}

fortify_fn(send) ssize_t 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 __orig_send(sockfd, buf, n, flags);
}

fortify_fn(sendto) ssize_t 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 __orig_sendto(sockfd, buf, n, flags, sa, salen);
}

#ifdef __cplusplus
}
#endif

#endif

#endif