Move the FORTIFY_SOURCE helpers over to .cpp.

Change-Id: Ib5067d51b983cac7760c975becce7fe2408ead04
This commit is contained in:
Elliott Hughes 2012-10-22 15:32:01 -07:00
parent df92635a57
commit 4035b7a321
17 changed files with 87 additions and 154 deletions

View File

@ -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 \
@ -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 \
@ -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 \
@ -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 \

View File

@ -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) {

View File

@ -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)) {

View File

@ -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) {

View File

@ -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");

View File

@ -1,59 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdarg.h>
/*
* 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.
*/
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;
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdarg.h>
/*
* 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.
*/
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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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.

View File

@ -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) {

View File

@ -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");

View File

@ -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)
@ -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;
}

View File

@ -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)
@ -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;
}