Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Move the FORTIFY_SOURCE helpers over to .cpp."
Browse files Browse the repository at this point in the history
  • Loading branch information
enh-google authored and Gerrit Code Review committed Oct 22, 2012
2 parents df92635 + 4035b7a commit 4e45775
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 154 deletions.
30 changes: 14 additions & 16 deletions libc/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ libc_common_src_files := \
bionic/eventfd.c \
bionic/fcntl.c \
bionic/fdprintf.c \
bionic/__fgets_chk.c \
bionic/__fgets_chk.cpp \
bionic/flockfile.c \
bionic/fork.c \
bionic/fstatfs.c \
Expand All @@ -205,12 +205,12 @@ libc_common_src_files := \
bionic/md5.c \
bionic/memccpy.c \
bionic/memchr.c \
bionic/__memcpy_chk.c \
bionic/__memcpy_chk.cpp \
bionic/memmem.c \
bionic/__memmove_chk.c \
bionic/__memmove_chk.cpp \
bionic/memmove_words.c \
bionic/memrchr.c \
bionic/__memset_chk.c \
bionic/__memset_chk.cpp \
bionic/memswap.c \
bionic/mmap.c \
bionic/openat.c \
Expand Down Expand Up @@ -252,19 +252,17 @@ libc_common_src_files := \
bionic/sigsuspend.c \
bionic/sigwait.c \
bionic/sleep.c \
bionic/__snprintf_chk.c \
bionic/__sprintf_chk.c \
bionic/statfs.c \
bionic/__strcat_chk.c \
bionic/__strcat_chk.cpp \
bionic/strcoll.c \
bionic/__strcpy_chk.c \
bionic/__strcpy_chk.cpp \
bionic/strerror.cpp \
bionic/strerror_r.cpp \
bionic/__strlcat_chk.c \
bionic/__strlcpy_chk.c \
bionic/__strlen_chk.c \
bionic/__strncat_chk.c \
bionic/__strncpy_chk.c \
bionic/__strlcat_chk.cpp \
bionic/__strlcpy_chk.cpp \
bionic/__strlen_chk.cpp \
bionic/__strncat_chk.cpp \
bionic/__strncpy_chk.cpp \
bionic/strndup.c \
bionic/strnlen.c \
bionic/strntoimax.c \
Expand All @@ -279,14 +277,14 @@ libc_common_src_files := \
bionic/thread_atexit.c \
bionic/time64.c \
bionic/tmpfile.cpp \
bionic/__umask_chk.c \
bionic/__umask_chk.cpp \
bionic/umount.c \
bionic/unlockpt.c \
bionic/usleep.c \
bionic/utime.c \
bionic/utmp.c \
bionic/__vsnprintf_chk.c \
bionic/__vsprintf_chk.c \
bionic/__vsnprintf_chk.cpp \
bionic/__vsprintf_chk.cpp \
bionic/wait.c \
bionic/wchar.c \
bionic/wcscoll.c \
Expand Down
2 changes: 1 addition & 1 deletion libc/bionic/__fgets_chk.c → libc/bionic/__fgets_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This fgets check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
char *__fgets_chk(char *dest, int supplied_size,
extern "C" char *__fgets_chk(char *dest, int supplied_size,
FILE *stream, size_t dest_len_from_compiler)
{
if (supplied_size < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* This memcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
void *__memcpy_chk(void *dest, const void *src,
extern "C" void *__memcpy_chk(void *dest, const void *src,
size_t copy_amount, size_t dest_len)
{
if (__builtin_expect(copy_amount > dest_len, 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This memmove check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
void *__memmove_chk (void *dest, const void *src,
extern "C" void *__memmove_chk (void *dest, const void *src,
size_t len, size_t dest_len)
{
if (len > dest_len) {
Expand Down
3 changes: 1 addition & 2 deletions libc/bionic/__memset_chk.c → libc/bionic/__memset_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
* This memset check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
void *__memset_chk (void *dest, int c, size_t n, size_t dest_len)
{
extern "C" void *__memset_chk (void *dest, int c, size_t n, size_t dest_len) {
if (n > dest_len) {
__libc_android_log_print(ANDROID_LOG_FATAL, "libc",
"*** memset buffer overflow detected ***\n");
Expand Down
59 changes: 0 additions & 59 deletions libc/bionic/__snprintf_chk.c

This file was deleted.

58 changes: 0 additions & 58 deletions libc/bionic/__sprintf_chk.c

This file was deleted.

3 changes: 1 addition & 2 deletions libc/bionic/__strcat_chk.c → libc/bionic/__strcat_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
* This strcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size)
{
extern "C" char *__strcat_chk (char *dest, const char *src, size_t dest_buf_size) {
// TODO: optimize so we don't scan src/dest twice.
size_t src_len = strlen(src);
size_t dest_len = strlen(dest);
Expand Down
3 changes: 1 addition & 2 deletions libc/bionic/__strcpy_chk.c → libc/bionic/__strcpy_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
* This strcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
char *__strcpy_chk (char *dest, const char *src, size_t dest_len)
{
extern "C" char *__strcpy_chk (char *dest, const char *src, size_t dest_len) {
// TODO: optimize so we don't scan src twice.
size_t src_len = strlen(src) + 1;
if (src_len > dest_len) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* This strlcat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
size_t __strlcat_chk(char *dest, const char *src,
extern "C" size_t __strlcat_chk(char *dest, const char *src,
size_t supplied_size, size_t dest_len_from_compiler)
{
if (supplied_size > dest_len_from_compiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* This strlcpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
size_t __strlcpy_chk(char *dest, const char *src,
extern "C" size_t __strlcpy_chk(char *dest, const char *src,
size_t supplied_size, size_t dest_len_from_compiler)
{
if (supplied_size > dest_len_from_compiler) {
Expand Down
3 changes: 1 addition & 2 deletions libc/bionic/__strlen_chk.c → libc/bionic/__strlen_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
*
* or anytime strlen reads beyond an object boundary.
*/
size_t __strlen_chk(const char *s, size_t s_len)
{
extern "C" size_t __strlen_chk(const char *s, size_t s_len) {
size_t ret = strlen(s);

if (__builtin_expect(ret >= s_len, 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* This strncat check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
char *__strncat_chk (char *dest, const char *src,
extern "C" char *__strncat_chk (char *dest, const char *src,
size_t len, size_t dest_buf_size)
{
// TODO: optimize so we don't scan src/dest twice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This strncpy check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
char *__strncpy_chk (char *dest, const char *src,
extern "C" char *__strncpy_chk (char *dest, const char *src,
size_t len, size_t dest_len)
{
if (len > dest_len) {
Expand Down
3 changes: 1 addition & 2 deletions libc/bionic/__umask_chk.c → libc/bionic/__umask_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
* This umask check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
mode_t __umask_chk(mode_t mode)
{
extern "C" mode_t __umask_chk(mode_t mode) {
if ((mode & 0777) != mode) {
__libc_android_log_print(ANDROID_LOG_FATAL, "libc",
"*** FORTIFY_SOURCE: umask called with invalid mask ***\n");
Expand Down
33 changes: 31 additions & 2 deletions libc/bionic/__vsnprintf_chk.c → libc/bionic/__vsnprintf_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
* This vsnprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
int __vsnprintf_chk(
extern "C" int __vsnprintf_chk(
char *dest,
size_t supplied_size,
int flags,
int /*flags*/,
size_t dest_len_from_compiler,
const char *format,
va_list va)
Expand All @@ -58,3 +58,32 @@ int __vsnprintf_chk(

return vsnprintf(dest, supplied_size, format, va);
}

/*
* Runtime implementation of __builtin____snprintf_chk.
*
* See
* http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
* http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
* for details.
*
* This snprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
extern "C" int __snprintf_chk(
char *dest,
size_t supplied_size,
int flags,
size_t dest_len_from_compiler,
const char *format, ...)
{
va_list va;
int retval;

va_start(va, format);
retval = __vsnprintf_chk(dest, supplied_size, flags,
dest_len_from_compiler, format, va);
va_end(va);

return retval;
}
32 changes: 30 additions & 2 deletions libc/bionic/__vsprintf_chk.c → libc/bionic/__vsprintf_chk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
* This vsprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
int __vsprintf_chk(
extern "C" int __vsprintf_chk(
char *dest,
int flags,
int /*flags*/,
size_t dest_len_from_compiler,
const char *format,
va_list va)
Expand All @@ -59,3 +59,31 @@ int __vsprintf_chk(

return ret;
}

/*
* Runtime implementation of __builtin____sprintf_chk.
*
* See
* http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
* http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
* for details.
*
* This sprintf check is called if _FORTIFY_SOURCE is defined and
* greater than 0.
*/
extern "C" int __sprintf_chk(
char *dest,
int flags,
size_t dest_len_from_compiler,
const char *format, ...)
{
va_list va;
int retval;

va_start(va, format);
retval = __vsprintf_chk(dest, flags,
dest_len_from_compiler, format, va);
va_end(va);

return retval;
}

0 comments on commit 4e45775

Please sign in to comment.