diff options
| author | sin | 2015-05-13 12:04:15 +0100 |
|---|---|---|
| committer | sin | 2015-05-13 12:05:29 +0100 |
| commit | 158782b3bb791eae3c97947944c7023452bfbc96 (patch) | |
| tree | b76e70744ab0a2f76d781a65a0456b1b010c54df /include/sys/socket.h | |
| parent | 316a48653315b4bc36d8c50b542471b18441c9d5 (diff) | |
Add fortify_fn() helper in fortify-headers.h
Diffstat (limited to 'include/sys/socket.h')
| -rw-r--r-- | include/sys/socket.h | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/include/sys/socket.h b/include/sys/socket.h index d7871ae..5db1cb1 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include_next <sys/socket.h> | 4 | #include_next <sys/socket.h> |
| 5 | 5 | ||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 7 | #include "../fortify-headers.h" | ||
| 7 | 8 | ||
| 8 | #ifdef __cplusplus | 9 | #ifdef __cplusplus |
| 9 | extern "C" { | 10 | extern "C" { |
| @@ -14,50 +15,42 @@ extern "C" { | |||
| 14 | #undef send | 15 | #undef send |
| 15 | #undef sendto | 16 | #undef sendto |
| 16 | 17 | ||
| 17 | __typeof__(recv) __recv_orig __asm__(__USER_LABEL_PREFIX__ "recv"); | 18 | fortify_fn(recv) ssize_t recv(int sockfd, void *buf, size_t n, int flags) |
| 18 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 19 | ssize_t recv(int sockfd, void *buf, size_t n, int flags) | ||
| 20 | { | 19 | { |
| 21 | size_t bos = __builtin_object_size(buf, 0); | 20 | size_t bos = __builtin_object_size(buf, 0); |
| 22 | 21 | ||
| 23 | if (n > bos) | 22 | if (n > bos) |
| 24 | __builtin_trap(); | 23 | __builtin_trap(); |
| 25 | return __recv_orig(sockfd, buf, n, flags); | 24 | return __orig_recv(sockfd, buf, n, flags); |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | __typeof__(recvfrom) __recvfrom_orig __asm__(__USER_LABEL_PREFIX__ "recvfrom"); | 27 | fortify_fn(recvfrom) ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags, |
| 29 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | 28 | struct sockaddr *sa, socklen_t *salen) |
| 30 | ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags, | ||
| 31 | struct sockaddr *sa, socklen_t *salen) | ||
| 32 | { | 29 | { |
| 33 | size_t bos = __builtin_object_size(buf, 0); | 30 | size_t bos = __builtin_object_size(buf, 0); |
| 34 | 31 | ||
| 35 | if (n > bos) | 32 | if (n > bos) |
| 36 | __builtin_trap(); | 33 | __builtin_trap(); |
| 37 | return __recvfrom_orig(sockfd, buf, n, flags, sa, salen); | 34 | return __orig_recvfrom(sockfd, buf, n, flags, sa, salen); |
| 38 | } | 35 | } |
| 39 | 36 | ||
| 40 | __typeof__(send) __send_orig __asm__(__USER_LABEL_PREFIX__ "send"); | 37 | fortify_fn(send) ssize_t send(int sockfd, const void *buf, size_t n, int flags) |
| 41 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 42 | ssize_t send(int sockfd, const void *buf, size_t n, int flags) | ||
| 43 | { | 38 | { |
| 44 | size_t bos = __builtin_object_size(buf, 0); | 39 | size_t bos = __builtin_object_size(buf, 0); |
| 45 | 40 | ||
| 46 | if (n > bos) | 41 | if (n > bos) |
| 47 | __builtin_trap(); | 42 | __builtin_trap(); |
| 48 | return __send_orig(sockfd, buf, n, flags); | 43 | return __orig_send(sockfd, buf, n, flags); |
| 49 | } | 44 | } |
| 50 | 45 | ||
| 51 | __typeof__(sendto) __sendto_orig __asm__(__USER_LABEL_PREFIX__ "sendto"); | 46 | fortify_fn(sendto) ssize_t sendto(int sockfd, const void *buf, size_t n, int flags, |
| 52 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | 47 | const struct sockaddr *sa, socklen_t salen) |
| 53 | ssize_t sendto(int sockfd, const void *buf, size_t n, int flags, | ||
| 54 | const struct sockaddr *sa, socklen_t salen) | ||
| 55 | { | 48 | { |
| 56 | size_t bos = __builtin_object_size(buf, 0); | 49 | size_t bos = __builtin_object_size(buf, 0); |
| 57 | 50 | ||
| 58 | if (n > bos) | 51 | if (n > bos) |
| 59 | __builtin_trap(); | 52 | __builtin_trap(); |
| 60 | return __sendto_orig(sockfd, buf, n, flags, sa, salen); | 53 | return __orig_sendto(sockfd, buf, n, flags, sa, salen); |
| 61 | } | 54 | } |
| 62 | 55 | ||
| 63 | #ifdef __cplusplus | 56 | #ifdef __cplusplus |
