diff options
| author | sin | 2015-02-04 14:58:32 +0000 |
|---|---|---|
| committer | sin | 2015-02-04 14:58:32 +0000 |
| commit | 91c0c1270f5f690d787a126fe20430ec6409eb9f (patch) | |
| tree | a6c24ac5b759858c718bfebb97eda90318fc6666 /include | |
| parent | cc262554a1078e572813e55ad031e146c33c8573 (diff) | |
Add recvfrom() checks
Diffstat (limited to 'include')
| -rw-r--r-- | include/sys/socket.h | 17 |
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"); | ||
| 27 | static inline __attribute__ ((always_inline)) | ||
| 28 | ssize_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 | ||
