fortify-headers

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

strings.h (1658B)


      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_STRINGS_H
     17 #define _FORTIFY_STRINGS_H
     18 
     19 #include_next <strings.h>
     20 
     21 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
     22 #include "fortify-headers.h"
     23 
     24 #ifdef __cplusplus
     25 extern "C" {
     26 #endif
     27 
     28 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
     29  || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
     30  || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
     31 #undef bcopy
     32 #undef bzero
     33 _FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n)
     34 {
     35 	size_t __bd = __builtin_object_size(__d, 0);
     36 	size_t __bs = __builtin_object_size(__s, 0);
     37 
     38 	if (__n > __bd || __n > __bs)
     39 		__builtin_trap();
     40 	return __orig_bcopy(__s, __d, __n);
     41 }
     42 
     43 _FORTIFY_FN(bzero) void bzero(void *__s, size_t __n)
     44 {
     45 	size_t __b = __builtin_object_size(__s, 0);
     46 
     47 	if (__n > __b)
     48 		__builtin_trap();
     49 	return __orig_bzero(__s, __n);
     50 }
     51 #endif
     52 
     53 #ifdef __cplusplus
     54 }
     55 #endif
     56 
     57 #endif
     58 
     59 #endif