2015-05-13 11:15:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Dimitris Papastamos <sin@2f30.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
#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-05-13 11:04:15 +00:00
|
|
|
fortify_fn(confstr) size_t confstr(int name, char *buf, size_t len)
|
2015-02-05 14:03:53 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (len > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_confstr(name, buf, len);
|
2015-02-05 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(getcwd) char *getcwd(char *buf, size_t len)
|
2015-02-05 14:07:14 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (len > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_getcwd(buf, len);
|
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-05-13 11:04:15 +00:00
|
|
|
fortify_fn(getdomainname) int getdomainname(char *name, size_t len)
|
2015-02-28 11:52:02 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(name, 0);
|
|
|
|
|
|
|
|
if (len > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_getdomainname(name, len);
|
2015-02-28 11:52:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(getgroups) int getgroups(int len, gid_t *set)
|
2015-02-28 12:00:25 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(set, 0);
|
|
|
|
|
2015-02-28 20:49:00 +00:00
|
|
|
if (len > bos / sizeof(gid_t))
|
2015-02-28 12:00:25 +00:00
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_getgroups(len, set);
|
2015-02-28 12:00:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(gethostname) int gethostname(char *name, size_t len)
|
2015-02-23 10:45:20 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(name, 0);
|
|
|
|
|
|
|
|
if (len > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_gethostname(name, len);
|
2015-02-23 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(getlogin_r) int getlogin_r(char *name, size_t len)
|
2015-02-25 10:31:30 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(name, 0);
|
|
|
|
|
|
|
|
if (len > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_getlogin_r(name, len);
|
2015-02-25 10:31:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(pread) ssize_t pread(int fd, void *buf, size_t n, off_t offset)
|
2015-01-30 09:44:49 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_pread(fd, buf, n, offset);
|
2015-01-30 09:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(read) ssize_t read(int fd, void *buf, size_t n)
|
2015-01-29 20:31:30 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_read(fd, buf, n);
|
2015-01-29 20:31:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(readlink) ssize_t readlink(const char *path, char *buf, size_t n)
|
2015-02-28 16:48:58 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_readlink(path, buf, n);
|
2015-02-28 16:48:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(readlinkat) ssize_t readlinkat(int fd, const char *path, char *buf, size_t n)
|
2015-02-28 16:48:58 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_readlinkat(fd, path, buf, n);
|
2015-02-28 16:48:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(ttyname_r) int ttyname_r(int fd, char *name, size_t n)
|
2015-02-28 15:30:25 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(name, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_ttyname_r(fd, name, n);
|
2015-02-28 15:30:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:04:15 +00:00
|
|
|
fortify_fn(write) ssize_t write(int fd, const void *buf, size_t n)
|
2015-02-24 19:34:37 +00:00
|
|
|
{
|
|
|
|
size_t bos = __builtin_object_size(buf, 0);
|
|
|
|
|
|
|
|
if (n > bos)
|
|
|
|
__builtin_trap();
|
2015-05-13 11:04:15 +00:00
|
|
|
return __orig_write(fd, buf, 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
|