diff options
| author | sin | 2015-03-13 11:00:46 +0000 |
|---|---|---|
| committer | sin | 2015-03-13 11:00:46 +0000 |
| commit | 9f8c543dc81f0c4239acae6713f5414eb7dc681d (patch) | |
| tree | 0c8dad17e27c510cc3c98502841aa1a75dfa3d1e /include/sys/socket.h | |
| parent | b211796d68c4a6b56f999534627791f3576b6135 (diff) | |
Rework fortify implementation to use extern inline
Overriding functions with macros is legal in C but a lot of software
is not prepared for it. Use the extern inline method to achieve the
same result.
Diffstat (limited to 'include/sys/socket.h')
| -rw-r--r-- | include/sys/socket.h | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/include/sys/socket.h b/include/sys/socket.h index 5e6d679..4602866 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h | |||
| @@ -6,62 +6,61 @@ | |||
| 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 | 7 | ||
| 8 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef recv | ||
| 10 | #undef recvfrom | ||
| 11 | #undef send | ||
| 12 | #undef sendto | ||
| 9 | 13 | ||
| 10 | static inline __attribute__ ((always_inline)) | 14 | extern ssize_t __recv_orig(int, void *, size_t, int) |
| 11 | ssize_t | 15 | __asm__(__USER_LABEL_PREFIX__ "recv"); |
| 12 | __fortify_recv(int sockfd, void *buf, size_t n, int flags) | 16 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 17 | ssize_t recv(int sockfd, void *buf, size_t n, int flags) | ||
| 13 | { | 18 | { |
| 14 | size_t bos = __builtin_object_size(buf, 0); | 19 | size_t bos = __builtin_object_size(buf, 0); |
| 15 | 20 | ||
| 16 | if (n > bos) | 21 | if (n > bos) |
| 17 | __builtin_trap(); | 22 | __builtin_trap(); |
| 18 | return recv(sockfd, buf, n, flags); | 23 | return __recv_orig(sockfd, buf, n, flags); |
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | static inline __attribute__ ((always_inline)) | 26 | extern ssize_t __recvfrom_orig(int, void *, size_t, int, struct sockaddr *, socklen_t *) |
| 22 | ssize_t | 27 | __asm__(__USER_LABEL_PREFIX__ "recvfrom"); |
| 23 | __fortify_recvfrom(int sockfd, void *buf, size_t n, int flags, | 28 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 24 | struct sockaddr *sa, socklen_t *salen) | 29 | ssize_t recvfrom(int sockfd, void *buf, size_t n, int flags, |
| 30 | struct sockaddr *sa, socklen_t *salen) | ||
| 25 | { | 31 | { |
| 26 | size_t bos = __builtin_object_size(buf, 0); | 32 | size_t bos = __builtin_object_size(buf, 0); |
| 27 | 33 | ||
| 28 | if (n > bos) | 34 | if (n > bos) |
| 29 | __builtin_trap(); | 35 | __builtin_trap(); |
| 30 | return recvfrom(sockfd, buf, n, flags, sa, salen); | 36 | return __recvfrom_orig(sockfd, buf, n, flags, sa, salen); |
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | static inline __attribute__ ((always_inline)) | 39 | extern ssize_t __send_orig(int, const void *, size_t, int) |
| 34 | ssize_t | 40 | __asm__(__USER_LABEL_PREFIX__ "send"); |
| 35 | __fortify_send(int sockfd, const void *buf, size_t n, int flags) | 41 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 42 | ssize_t send(int sockfd, const void *buf, size_t n, int flags) | ||
| 36 | { | 43 | { |
| 37 | size_t bos = __builtin_object_size(buf, 0); | 44 | size_t bos = __builtin_object_size(buf, 0); |
| 38 | 45 | ||
| 39 | if (n > bos) | 46 | if (n > bos) |
| 40 | __builtin_trap(); | 47 | __builtin_trap(); |
| 41 | return send(sockfd, buf, n, flags); | 48 | return __send_orig(sockfd, buf, n, flags); |
| 42 | } | 49 | } |
| 43 | 50 | ||
| 44 | static inline __attribute__ ((always_inline)) | 51 | extern ssize_t __sendto_orig(int, const void *, size_t, int, const struct sockaddr *, socklen_t) |
| 45 | ssize_t | 52 | __asm__(__USER_LABEL_PREFIX__ "sendto"); |
| 46 | __fortify_sendto(int sockfd, const void *buf, size_t n, int flags, | 53 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 47 | const struct sockaddr *sa, socklen_t salen) | 54 | ssize_t sendto(int sockfd, const void *buf, size_t n, int flags, |
| 55 | const struct sockaddr *sa, socklen_t salen) | ||
| 48 | { | 56 | { |
| 49 | size_t bos = __builtin_object_size(buf, 0); | 57 | size_t bos = __builtin_object_size(buf, 0); |
| 50 | 58 | ||
| 51 | if (n > bos) | 59 | if (n > bos) |
| 52 | __builtin_trap(); | 60 | __builtin_trap(); |
| 53 | return sendto(sockfd, buf, n, flags, sa, salen); | 61 | return __sendto_orig(sockfd, buf, n, flags, sa, salen); |
| 54 | } | 62 | } |
| 55 | 63 | ||
| 56 | #undef recv | ||
| 57 | #define recv(sockfd, buf, n, flags) __fortify_recv(sockfd, buf, n, flags) | ||
| 58 | #undef recvfrom | ||
| 59 | #define recvfrom(sockfd, buf, n, flags, sa, salen) __fortify_recvfrom(sockfd, buf, n, flags, sa, salen) | ||
| 60 | #undef send | ||
| 61 | #define send(sockfd, buf, n, flags) __fortify_send(sockfd, buf, n, flags) | ||
| 62 | #undef sendto | ||
| 63 | #define sendto(sockfd, buf, n, flags, sa, salen) __fortify_sendto(sockfd, buf, n, flags, sa, salen) | ||
| 64 | |||
| 65 | #endif | 64 | #endif |
| 66 | 65 | ||
| 67 | #endif | 66 | #endif |
