libc: upgrade some libc functions to _FORTIFY_SOURCE=2

Upgrade the following functions:

* vsnprintf
* vsprintf
* snprintf
* fgets
* strcpy
* strcat
* strncat
* strlcpy
* strlcat
* strlen
* strchr

Change-Id: Icc036fc7f0bb317e05f7c051617887a1601271aa
This commit is contained in:
Nick Kralevich 2013-04-30 11:31:35 -07:00
parent b94b2851d7
commit 9020fd503c
2 changed files with 11 additions and 13 deletions

View File

@ -466,8 +466,7 @@ __attribute__((__format__ (printf, 3, 0)))
__attribute__((__nonnull__ (3)))
int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
{
return __builtin___vsnprintf_chk(dest, size, 0,
__builtin_object_size(dest, 0), format, ap);
return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
}
__BIONIC_FORTIFY_INLINE
@ -475,8 +474,7 @@ __attribute__((__format__ (printf, 2, 0)))
__attribute__((__nonnull__ (2)))
int vsprintf(char *dest, const char *format, __va_list ap)
{
return __builtin___vsprintf_chk(dest, 0,
__builtin_object_size(dest, 0), format, ap);
return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
}
__BIONIC_FORTIFY_INLINE
@ -485,7 +483,7 @@ __attribute__((__nonnull__ (3)))
int snprintf(char *str, size_t size, const char *format, ...)
{
return __builtin___snprintf_chk(str, size, 0,
__builtin_object_size(str, 0), format, __builtin_va_arg_pack());
__bos(str), format, __builtin_va_arg_pack());
}
__BIONIC_FORTIFY_INLINE
@ -508,7 +506,7 @@ extern char *__fgets_chk(char *, int, FILE *, size_t);
__BIONIC_FORTIFY_INLINE
char *fgets(char *dest, int size, FILE *stream)
{
size_t bos = __builtin_object_size(dest, 0);
size_t bos = __bos(dest);
// Compiler can prove, at compile time, that the passed in size
// is always negative. Force a compiler error.

View File

@ -116,7 +116,7 @@ void *memmove (void *dest, const void *src, size_t len) {
__BIONIC_FORTIFY_INLINE
char *strcpy(char *dest, const char *src) {
return __builtin___strcpy_chk(dest, src, __builtin_object_size (dest, 0));
return __builtin___strcpy_chk(dest, src, __bos(dest));
}
extern void __strncpy_error()
@ -133,12 +133,12 @@ char *strncpy(char *dest, const char *src, size_t n) {
__BIONIC_FORTIFY_INLINE
char *strcat(char *dest, const char *src) {
return __builtin___strcat_chk(dest, src, __builtin_object_size (dest, 0));
return __builtin___strcat_chk(dest, src, __bos(dest));
}
__BIONIC_FORTIFY_INLINE
char *strncat(char *dest, const char *src, size_t n) {
return __builtin___strncat_chk(dest, src, n, __builtin_object_size (dest, 0));
return __builtin___strncat_chk(dest, src, n, __bos(dest));
}
__BIONIC_FORTIFY_INLINE
@ -154,7 +154,7 @@ extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
__BIONIC_FORTIFY_INLINE
size_t strlcpy(char *dest, const char *src, size_t size) {
size_t bos = __builtin_object_size(dest, 0);
size_t bos = __bos(dest);
// Compiler doesn't know destination size. Don't call __strlcpy_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
@ -185,7 +185,7 @@ extern size_t __strlcat_chk(char *, const char *, size_t, size_t);
__BIONIC_FORTIFY_INLINE
size_t strlcat(char *dest, const char *src, size_t size) {
size_t bos = __builtin_object_size(dest, 0);
size_t bos = __bos(dest);
// Compiler doesn't know destination size. Don't call __strlcat_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
@ -211,7 +211,7 @@ 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);
size_t bos = __bos(s);
// Compiler doesn't know destination size. Don't call __strlen_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
@ -230,7 +230,7 @@ extern char* __strchr_chk(const char *, int, size_t);
__BIONIC_FORTIFY_INLINE
char* strchr(const char *s, int c) {
size_t bos = __builtin_object_size(s, 0);
size_t bos = __bos(s);
// Compiler doesn't know destination size. Don't call __strchr_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {