socket2.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Checking macros for socket functions.
  2. Copyright (C) 2005-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_SOCKET_H
  16. # error "Never include <bits/socket2.h> directly; use <sys/socket.h> instead."
  17. #endif
  18. extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
  19. int __flags);
  20. extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
  21. int __flags), recv);
  22. extern ssize_t __REDIRECT (__recv_chk_warn,
  23. (int __fd, void *__buf, size_t __n, size_t __buflen,
  24. int __flags), __recv_chk)
  25. __warnattr ("recv called with bigger length than size of destination "
  26. "buffer");
  27. __fortify_function __attribute_overloadable__ ssize_t
  28. recv (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf), size_t __n,
  29. int __flags)
  30. __fortify_clang_warning_only_if_bos0_lt (__n, __buf,
  31. "recv called with bigger length than "
  32. "size of destination buffer")
  33. {
  34. size_t __sz = __glibc_objsize0 (__buf);
  35. if (__glibc_safe_or_unknown_len (__n, sizeof (char), __sz))
  36. return __recv_alias (__fd, __buf, __n, __flags);
  37. #if !__fortify_use_clang
  38. if (__glibc_unsafe_len (__n, sizeof (char), __sz))
  39. return __recv_chk_warn (__fd, __buf, __n, __sz, __flags);
  40. #endif
  41. return __recv_chk (__fd, __buf, __n, __sz, __flags);
  42. }
  43. extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
  44. size_t __buflen, int __flags,
  45. __SOCKADDR_ARG __addr,
  46. socklen_t *__restrict __addr_len);
  47. extern ssize_t __REDIRECT (__recvfrom_alias,
  48. (int __fd, void *__restrict __buf, size_t __n,
  49. int __flags, __SOCKADDR_ARG __addr,
  50. socklen_t *__restrict __addr_len), recvfrom);
  51. extern ssize_t __REDIRECT (__recvfrom_chk_warn,
  52. (int __fd, void *__restrict __buf, size_t __n,
  53. size_t __buflen, int __flags,
  54. __SOCKADDR_ARG __addr,
  55. socklen_t *__restrict __addr_len), __recvfrom_chk)
  56. __warnattr ("recvfrom called with bigger length than size of "
  57. "destination buffer");
  58. __fortify_function __attribute_overloadable__ ssize_t
  59. recvfrom (int __fd, __fortify_clang_overload_arg0 (void *, __restrict, __buf),
  60. size_t __n, int __flags,
  61. __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
  62. __fortify_clang_warning_only_if_bos0_lt (__n, __buf,
  63. "recvfrom called with bigger length "
  64. "than size of destination buffer")
  65. {
  66. size_t __sz = __glibc_objsize0 (__buf);
  67. if (__glibc_safe_or_unknown_len (__n, sizeof (char), __sz))
  68. return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
  69. #if !__fortify_use_clang
  70. if (__glibc_unsafe_len (__n, sizeof (char), __sz))
  71. return __recvfrom_chk_warn (__fd, __buf, __n, __sz, __flags, __addr,
  72. __addr_len);
  73. #endif
  74. return __recvfrom_chk (__fd, __buf, __n, __sz, __flags, __addr, __addr_len);
  75. }