socket.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2015 Dimitris Papastamos <sin@2f30.org>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #ifndef _FORTIFY_SYS_SOCKET_H
  16. #define _FORTIFY_SYS_SOCKET_H
  17. __extension__
  18. #include_next <sys/socket.h>
  19. #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
  20. #include "../fortify-headers.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #undef recv
  25. #undef recvfrom
  26. #undef send
  27. #undef sendto
  28. _FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
  29. {
  30. size_t __b = __builtin_object_size(__s, 0);
  31. if (__n > __b)
  32. __builtin_trap();
  33. return __orig_recv(__f, __s, __n, __fl);
  34. }
  35. _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
  36. struct sockaddr *__a, socklen_t *__l)
  37. {
  38. size_t __b = __builtin_object_size(__s, 0);
  39. if (__n > __b)
  40. __builtin_trap();
  41. return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
  42. }
  43. _FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
  44. {
  45. size_t __b = __builtin_object_size(__s, 0);
  46. if (__n > __b)
  47. __builtin_trap();
  48. return __orig_send(__f, __s, __n, __fl);
  49. }
  50. _FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl,
  51. const struct sockaddr *__a, socklen_t __l)
  52. {
  53. size_t __b = __builtin_object_size(__s, 0);
  54. if (__n > __b)
  55. __builtin_trap();
  56. return __orig_sendto(__f, __s, __n, __fl, __a, __l);
  57. }
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif
  62. #endif