diff options
| author | Nick Kralevich <nnk@google.com> | 2013-08-28 13:22:52 -0700 |
|---|---|---|
| committer | Nick Kralevich <nnk@google.com> | 2013-08-28 14:27:14 -0700 |
| commit | bd8e6749b78567af62ec126d7cc057386ebee25a (patch) | |
| tree | 949ca8147c4675afb9f0af51e404f535dbd38a93 /libc | |
| parent | eb8f36223e51db626a23b8032f03c095be80998b (diff) | |
| download | bionic-bd8e6749b78567af62ec126d7cc057386ebee25a.zip bionic-bd8e6749b78567af62ec126d7cc057386ebee25a.tar.gz bionic-bd8e6749b78567af62ec126d7cc057386ebee25a.tar.bz2 | |
cdefs.h: introduce __bos0
Introduce __bos0 as a #define for __builtin_object_size((s), 0).
This macro is intended to be used for places where the standard
__bos macro isn't appropriate.
memcpy, memmove, and memset deliberately use __bos0. This is done
for two reasons:
1) I haven't yet tested to see if __bos is safe to use.
2) glibc uses __bos0 for these methods.
Change-Id: Ifbe02efdb10a72fe3529dbcc47ff647bde6feeca
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/include/string.h | 8 | ||||
| -rw-r--r-- | libc/include/sys/cdefs.h | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/libc/include/string.h b/libc/include/string.h index 5409391..f6b4acf 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -94,8 +94,8 @@ __BIONIC_FORTIFY_INLINE void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) { char *d = (char *) dest; const char *s = (const char *) src; - size_t s_len = __builtin_object_size(s, 0); - size_t d_len = __builtin_object_size(d, 0); + size_t s_len = __bos0(s); + size_t d_len = __bos0(d); if (__builtin_constant_p(copy_amount) && (copy_amount > d_len)) { __memcpy_dest_size_error(); @@ -110,7 +110,7 @@ void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amou __BIONIC_FORTIFY_INLINE void* memmove(void *dest, const void *src, size_t len) { - return __builtin___memmove_chk(dest, src, len, __builtin_object_size (dest, 0)); + return __builtin___memmove_chk(dest, src, len, __bos0(dest)); } __BIONIC_FORTIFY_INLINE @@ -153,7 +153,7 @@ char *strncat(char* __restrict dest, const char* __restrict src, size_t n) { __BIONIC_FORTIFY_INLINE void* memset(void *s, int c, size_t n) { - return __builtin___memset_chk(s, c, n, __builtin_object_size (s, 0)); + return __builtin___memset_chk(s, c, n, __bos0(s)); } extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index a4c1aff..175c28b 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -526,6 +526,14 @@ #define __BIONIC__ 1 #include <android/api-level.h> +/* + * When _FORTIFY_SOURCE is defined, automatic bounds checking is + * added to commonly used libc functions. If a buffer overrun is + * detected, the program is safely aborted. + * + * See + * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for details. + */ #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 #define __BIONIC_FORTIFY 1 #if _FORTIFY_SOURCE == 2 @@ -533,6 +541,7 @@ #else #define __bos(s) __builtin_object_size((s), 0) #endif +#define __bos0(s) __builtin_object_size((s), 0) #define __BIONIC_FORTIFY_INLINE \ extern inline \ |
