2015-05-13 11:15:36 +00:00
|
|
|
/*
|
2016-09-10 11:54:06 +00:00
|
|
|
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
|
2015-05-13 11:15:36 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-03-11 18:55:51 +00:00
|
|
|
#ifndef _FORTIFY_UNISTD_H
|
|
|
|
#define _FORTIFY_UNISTD_H
|
2015-01-29 20:31:30 +00:00
|
|
|
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#ifndef __cplusplus
|
2015-06-24 18:13:37 +00:00
|
|
|
__extension__
|
Don't use __extension__ in C++ code
A few important notes:
* __extension__ is a GNU C "alternate" keyword, not a C++ keyword.[1]
* __extension__ is designed to work on "expressions"; it does work on
#include_next in C mode, but it has no effect in C++ mode; the
warning will still appear, if enabled, even with __extension__
preceding #include_next. This is because #include_next is not
considered an expression in C++, so the compiler attaches
__extension__ to the first expression of the header.
All of this leads us to a build failure while building at least all
Mozilla software. Moz has an alternate -isystem dir searched before
/usr/include that overrides some headers, including <features.h>. The
first statement in each of these headers is a #pragma, and since
__extension__ is looking for an expression, and #pragma is a "null"
expression, we end up with the following error:
dist/system_wrappers/features.h:1:9: error: '#pragma' is not allowed here
Since __extension__ has no effect on #include_next in C++ mode anyway,
and since it can cause breakage, this commit omits __extension__ in C++
mode.
[1]: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Alternate-Keywords.html
2018-06-23 22:57:48 +00:00
|
|
|
#endif
|
2015-01-29 20:31:30 +00:00
|
|
|
#include_next <unistd.h>
|
|
|
|
|
|
|
|
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
2015-05-13 11:04:15 +00:00
|
|
|
#include "fortify-headers.h"
|
2015-01-29 20:31:30 +00:00
|
|
|
|
2015-03-13 23:09:15 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-03-13 11:00:46 +00:00
|
|
|
#undef confstr
|
|
|
|
#undef getcwd
|
|
|
|
#undef getgroups
|
|
|
|
#undef gethostname
|
|
|
|
#undef getlogin_r
|
|
|
|
#undef pread
|
|
|
|
#undef read
|
|
|
|
#undef readlink
|
|
|
|
#undef readlinkat
|
|
|
|
#undef ttyname_r
|
|
|
|
#undef write
|
2015-03-11 09:26:11 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l)
|
2015-02-05 14:03:53 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-07-15 15:05:52 +00:00
|
|
|
size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b);
|
2015-02-05 14:03:53 +00:00
|
|
|
|
2015-07-15 15:05:52 +00:00
|
|
|
if (__l > __b && __r > __b)
|
2015-02-05 14:03:53 +00:00
|
|
|
__builtin_trap();
|
2015-07-15 15:05:52 +00:00
|
|
|
return __r;
|
2015-02-05 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)
|
2015-02-05 14:07:14 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-05 14:07:14 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__l > __b)
|
2015-02-05 14:07:14 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_getcwd(__s, __l);
|
2015-02-05 14:07:14 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 11:52:02 +00:00
|
|
|
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
2015-03-13 11:00:46 +00:00
|
|
|
#undef getdomainname
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l)
|
2015-02-28 11:52:02 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-28 11:52:02 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__l > __b)
|
2015-02-28 11:52:02 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_getdomainname(__s, __l);
|
2015-02-28 11:52:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s)
|
2015-02-28 12:00:25 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-28 12:00:25 +00:00
|
|
|
|
2019-03-13 12:55:48 +00:00
|
|
|
if (__l > 0 && (unsigned)__l > __b / sizeof(gid_t))
|
2015-02-28 12:00:25 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_getgroups(__l, __s);
|
2015-02-28 12:00:25 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l)
|
2015-02-23 10:45:20 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-23 10:45:20 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__l > __b)
|
2015-02-23 10:45:20 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_gethostname(__s, __l);
|
2015-02-23 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l)
|
2015-02-25 10:31:30 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-25 10:31:30 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__l > __b)
|
2015-02-25 10:31:30 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_getlogin_r(__s, __l);
|
2015-02-25 10:31:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o)
|
2015-01-30 09:44:49 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-01-30 09:44:49 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-01-30 09:44:49 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_pread(__f, __s, __n, __o);
|
2015-01-30 09:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n)
|
2015-01-29 20:31:30 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-01-29 20:31:30 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-01-29 20:31:30 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_read(__f, __s, __n);
|
2015-01-29 20:31:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n)
|
2015-02-28 16:48:58 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-28 16:48:58 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-02-28 16:48:58 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_readlink(__p, __s, __n);
|
2015-02-28 16:48:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, size_t __n)
|
2015-02-28 16:48:58 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-28 16:48:58 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-02-28 16:48:58 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_readlinkat(__f, __p, __s, __n);
|
2015-02-28 16:48:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n)
|
2015-02-28 15:30:25 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-28 15:30:25 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-02-28 15:30:25 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_ttyname_r(__f, __s, __n);
|
2015-02-28 15:30:25 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
_FORTIFY_FN(write) ssize_t write(int __f, const void *__s, size_t __n)
|
2015-02-24 19:34:37 +00:00
|
|
|
{
|
2015-06-03 17:27:01 +00:00
|
|
|
size_t __b = __builtin_object_size(__s, 0);
|
2015-02-24 19:34:37 +00:00
|
|
|
|
2015-06-03 17:27:01 +00:00
|
|
|
if (__n > __b)
|
2015-02-24 19:34:37 +00:00
|
|
|
__builtin_trap();
|
2015-06-03 17:27:01 +00:00
|
|
|
return __orig_write(__f, __s, __n);
|
2015-02-24 19:34:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 23:09:15 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2015-03-11 09:26:11 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-29 20:31:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|