From eecef18261cc278fbc13ecbfb4e5bc10762cc794 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 24 Feb 2015 18:12:27 +0000 Subject: Remove compile time checks These can produce false positives. Given that we support fortify source level 1 we shouldn't break valid code. --- include/string.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'include/string.h') diff --git a/include/string.h b/include/string.h index 9f69d31..9d40e77 100644 --- a/include/string.h +++ b/include/string.h @@ -5,9 +5,6 @@ #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 -#define __errordecl(name, msg) extern void name(void) __attribute__ ((__error__(msg))) - -__errordecl(__memcpy_error, "memcpy: buffer overflow detected"); static inline __attribute__ ((always_inline)) void * __fortify_memcpy(void *dest, const void *src, size_t n) @@ -16,9 +13,6 @@ __fortify_memcpy(void *dest, const void *src, size_t n) char *d = dest; const char *s = src; - if (__builtin_constant_p(n) && n > bos) - __memcpy_error(); - /* trap if pointers are overlapping but not if dest == src */ if ((d < s && d + n > s) || (s < d && s + n > d)) @@ -28,31 +22,23 @@ __fortify_memcpy(void *dest, const void *src, size_t n) return memcpy(dest, src, n); } -__errordecl(__memmove_error, "memmove: buffer overflow detected"); static inline __attribute__ ((always_inline)) void * __fortify_memmove(void *dest, const void *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __memmove_error(); - if (n > bos) __builtin_trap(); return memmove(dest, src, n); } -__errordecl(__memset_error, "memset: buffer overflow detected"); static inline __attribute__ ((always_inline)) void * __fortify_memset(void *dest, int c, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __memset_error(); - if (n > bos) __builtin_trap(); return memset(dest, c, n); @@ -69,16 +55,12 @@ __fortify_stpcpy(char *dest, const char *src) return stpcpy(dest, src); } -__errordecl(__stpncpy_error, "stpncpy: buffer overflow detected"); static inline __attribute__ ((always_inline)) char * __fortify_stpncpy(char *dest, const char *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __stpncpy_error(); - if (n > bos) __builtin_trap(); return stpncpy(dest, src, n); @@ -106,7 +88,6 @@ __fortify_strcpy(char *dest, const char *src) return strcpy(dest, src); } -__errordecl(__strncat_error, "strncat: buffer overflow detected"); static inline __attribute__ ((always_inline)) char * __fortify_strncat(char *dest, const char *src, size_t n) @@ -114,9 +95,6 @@ __fortify_strncat(char *dest, const char *src, size_t n) size_t bos = __builtin_object_size(dest, 0); size_t slen, dlen; - if (__builtin_constant_p(n) && n > bos) - __strncat_error(); - if (n > bos) { slen = strlen(src); dlen = strlen(dest); @@ -128,32 +106,24 @@ __fortify_strncat(char *dest, const char *src, size_t n) return strncat(dest, src, n); } -__errordecl(__strncpy_error, "strncpy: buffer overflow detected"); static inline __attribute__ ((always_inline)) char * __fortify_strncpy(char *dest, const char *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __strncpy_error(); - if (n > bos) __builtin_trap(); return strncpy(dest, src, n); } #ifdef _GNU_SOURCE -__errordecl(__mempcpy_error, "mempcpy: buffer overflow detected"); static inline __attribute__ ((always_inline)) void * __fortify_mempcpy(void *dest, const void *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __mempcpy_error(); - if (n > bos) __builtin_trap(); return mempcpy(dest, src, n); @@ -161,31 +131,23 @@ __fortify_mempcpy(void *dest, const void *src, size_t n) #endif #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__errordecl(__strlcat_error, "strlcat: buffer overflow detected"); static inline __attribute__ ((always_inline)) size_t __fortify_strlcat(char *dest, const char *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __strlcat_error(); - if (n > bos) __builtin_trap(); return strlcat(dest, src, n); } -__errordecl(__strlcpy_error, "strlcpy: buffer overflow detected"); static inline __attribute__ ((always_inline)) size_t __fortify_strlcpy(char *dest, const char *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - if (__builtin_constant_p(n) && n > bos) - __strlcpy_error(); - if (n > bos) __builtin_trap(); return strlcpy(dest, src, n); @@ -223,8 +185,6 @@ __fortify_strlcpy(char *dest, const char *src, size_t n) #define strlcpy(dest, src, n) __fortify_strlcpy(dest, src, n) #endif -#undef __errordecl - #endif #endif -- cgit v1.3