fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers.git
Log | Files | Refs | README | LICENSE

socket.h (2123B)


      1 /*
      2  * Copyright (C) 2015-2016 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 
     16 #ifndef _FORTIFY_SYS_SOCKET_H
     17 #define _FORTIFY_SYS_SOCKET_H
     18 
     19 #ifndef __cplusplus
     20 __extension__
     21 #endif
     22 #include_next <sys/socket.h>
     23 
     24 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
     25 #include "../fortify-headers.h"
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #undef recv
     32 #undef recvfrom
     33 #undef send
     34 #undef sendto
     35 
     36 _FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
     37 {
     38 	size_t __b = __builtin_object_size(__s, 0);
     39 
     40 	if (__n > __b)
     41 		__builtin_trap();
     42 	return __orig_recv(__f, __s, __n, __fl);
     43 }
     44 
     45 _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
     46                                        struct sockaddr *__a, socklen_t *__l)
     47 {
     48 	size_t __b = __builtin_object_size(__s, 0);
     49 
     50 	if (__n > __b)
     51 		__builtin_trap();
     52 	return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
     53 }
     54 
     55 _FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
     56 {
     57 	size_t __b = __builtin_object_size(__s, 0);
     58 
     59 	if (__n > __b)
     60 		__builtin_trap();
     61 	return __orig_send(__f, __s, __n, __fl);
     62 }
     63 
     64 _FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl,
     65                                    const struct sockaddr *__a, socklen_t __l)
     66 {
     67 	size_t __b = __builtin_object_size(__s, 0);
     68 
     69 	if (__n > __b)
     70 		__builtin_trap();
     71 	return __orig_sendto(__f, __s, __n, __fl, __a, __l);
     72 }
     73 
     74 #ifdef __cplusplus
     75 }
     76 #endif
     77 
     78 #endif
     79 
     80 #endif