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