From 9b6cc223a36835c4367a036d4cfeff14d25bc742 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 13 Jul 2012 14:46:36 -0700 Subject: [PATCH] FORTIFY_SOURCE: introduce __BIONIC_FORTIFY_UNKNOWN_SIZE macro Replace all occurances of "(size_t) -1" with a __BIONIC_FORTIFY_UNKNOWN_SIZE macro. Change-Id: I0b188f6cf31417d2dbef0e1bd759de3f9782873a --- libc/include/stdio.h | 2 +- libc/include/string.h | 9 ++++++--- libc/include/sys/cdefs.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index c12ddb812..453cf0b94 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -547,7 +547,7 @@ char *fgets(char *dest, int size, FILE *stream) } // Compiler doesn't know destination size. Don't call __fgets_chk - if (bos == (size_t) -1) { + if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { return __fgets_real(dest, size, stream); } diff --git a/libc/include/string.h b/libc/include/string.h index 842aa3922..8730ea3f4 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -166,7 +166,7 @@ size_t strlcpy(char *dest, const char *src, size_t size) { size_t bos = __builtin_object_size(dest, 0); // Compiler doesn't know destination size. Don't call __strlcpy_chk - if (bos == (size_t) -1) { + if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { return __strlcpy_real(dest, src, size); } @@ -197,7 +197,7 @@ size_t strlcat(char *dest, const char *src, size_t size) { size_t bos = __builtin_object_size(dest, 0); // Compiler doesn't know destination size. Don't call __strlcat_chk - if (bos == (size_t) -1) { + if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { return __strlcat_real(dest, src, size); } @@ -223,9 +223,12 @@ extern size_t __strlen_chk(const char *, size_t); __BIONIC_FORTIFY_INLINE size_t strlen(const char *s) { size_t bos = __builtin_object_size(s, 0); - if (bos == (size_t) -1) { + + // Compiler doesn't know destination size. Don't call __strlen_chk + if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { return __strlen_real(s); } + return __strlen_chk(s, bos); } diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index 1ba9100b9..987a5e3db 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -507,6 +507,7 @@ __attribute__ ((always_inline)) \ __attribute__ ((gnu_inline)) \ __attribute__ ((artificial)) +#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1) #endif #endif /* !_SYS_CDEFS_H_ */