am 382a7753: Merge "strncpy: implement _FORTIFY_SOURCE=2"

* commit '382a7753786646483a8101f4e337f9e3a82ec852':
  strncpy: implement _FORTIFY_SOURCE=2
This commit is contained in:
Nick Kralevich
2013-04-29 16:25:41 -07:00
committed by Android Git Automerger
6 changed files with 137 additions and 34 deletions

View File

@@ -119,9 +119,16 @@ char *strcpy(char *dest, const char *src) {
return __builtin___strcpy_chk(dest, src, __builtin_object_size (dest, 0));
}
extern void __strncpy_error()
__attribute__((__error__("strncpy called with size bigger than buffer")));
__BIONIC_FORTIFY_INLINE
char *strncpy(char *dest, const char *src, size_t n) {
return __builtin___strncpy_chk(dest, src, n, __builtin_object_size (dest, 0));
size_t bos = __bos(dest);
if (__builtin_constant_p(n) && (n > bos)) {
__strncpy_error();
}
return __builtin___strncpy_chk(dest, src, n, bos);
}
__BIONIC_FORTIFY_INLINE

View File

@@ -517,6 +517,12 @@
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 && !defined(__clang__)
#define __BIONIC_FORTIFY 1
#if _FORTIFY_SOURCE == 2
#define __bos(s) __builtin_object_size((s), 1);
#else
#define __bos(s) __builtin_object_size((s), 0);
#endif
#define __BIONIC_FORTIFY_INLINE \
extern inline \
__attribute__ ((always_inline)) \