diff options
| author | sin | 2015-05-13 12:04:15 +0100 |
|---|---|---|
| committer | sin | 2015-05-13 12:05:29 +0100 |
| commit | 158782b3bb791eae3c97947944c7023452bfbc96 (patch) | |
| tree | b76e70744ab0a2f76d781a65a0456b1b010c54df /include/unistd.h | |
| parent | 316a48653315b4bc36d8c50b542471b18441c9d5 (diff) | |
Add fortify_fn() helper in fortify-headers.h
Diffstat (limited to 'include/unistd.h')
| -rw-r--r-- | include/unistd.h | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/include/unistd.h b/include/unistd.h index 318fcc5..23a8341 100644 --- a/include/unistd.h +++ b/include/unistd.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include_next <unistd.h> | 4 | #include_next <unistd.h> |
| 5 | 5 | ||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 7 | #include "fortify-headers.h" | ||
| 7 | 8 | ||
| 8 | #ifdef __cplusplus | 9 | #ifdef __cplusplus |
| 9 | extern "C" { | 10 | extern "C" { |
| @@ -21,139 +22,115 @@ extern "C" { | |||
| 21 | #undef ttyname_r | 22 | #undef ttyname_r |
| 22 | #undef write | 23 | #undef write |
| 23 | 24 | ||
| 24 | __typeof__(confstr) __confstr_orig __asm__(__USER_LABEL_PREFIX__ "confstr"); | 25 | fortify_fn(confstr) size_t confstr(int name, char *buf, size_t len) |
| 25 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 26 | size_t confstr(int name, char *buf, size_t len) | ||
| 27 | { | 26 | { |
| 28 | size_t bos = __builtin_object_size(buf, 0); | 27 | size_t bos = __builtin_object_size(buf, 0); |
| 29 | 28 | ||
| 30 | if (len > bos) | 29 | if (len > bos) |
| 31 | __builtin_trap(); | 30 | __builtin_trap(); |
| 32 | return __confstr_orig(name, buf, len); | 31 | return __orig_confstr(name, buf, len); |
| 33 | } | 32 | } |
| 34 | 33 | ||
| 35 | __typeof__(getcwd) __getcwd_orig __asm__(__USER_LABEL_PREFIX__ "getcwd"); | 34 | fortify_fn(getcwd) char *getcwd(char *buf, size_t len) |
| 36 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 37 | char *getcwd(char *buf, size_t len) | ||
| 38 | { | 35 | { |
| 39 | size_t bos = __builtin_object_size(buf, 0); | 36 | size_t bos = __builtin_object_size(buf, 0); |
| 40 | 37 | ||
| 41 | if (len > bos) | 38 | if (len > bos) |
| 42 | __builtin_trap(); | 39 | __builtin_trap(); |
| 43 | return __getcwd_orig(buf, len); | 40 | return __orig_getcwd(buf, len); |
| 44 | } | 41 | } |
| 45 | 42 | ||
| 46 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 43 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 47 | #undef getdomainname | 44 | #undef getdomainname |
| 48 | __typeof__(getdomainname) __getdomainname_orig __asm__(__USER_LABEL_PREFIX__ "getdomainname"); | 45 | fortify_fn(getdomainname) int getdomainname(char *name, size_t len) |
| 49 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 50 | int getdomainname(char *name, size_t len) | ||
| 51 | { | 46 | { |
| 52 | size_t bos = __builtin_object_size(name, 0); | 47 | size_t bos = __builtin_object_size(name, 0); |
| 53 | 48 | ||
| 54 | if (len > bos) | 49 | if (len > bos) |
| 55 | __builtin_trap(); | 50 | __builtin_trap(); |
| 56 | return __getdomainname_orig(name, len); | 51 | return __orig_getdomainname(name, len); |
| 57 | } | 52 | } |
| 58 | #endif | 53 | #endif |
| 59 | 54 | ||
| 60 | __typeof__(getgroups) __getgroups_orig __asm__(__USER_LABEL_PREFIX__ "getgroups"); | 55 | fortify_fn(getgroups) int getgroups(int len, gid_t *set) |
| 61 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 62 | int getgroups(int len, gid_t *set) | ||
| 63 | { | 56 | { |
| 64 | size_t bos = __builtin_object_size(set, 0); | 57 | size_t bos = __builtin_object_size(set, 0); |
| 65 | 58 | ||
| 66 | if (len > bos / sizeof(gid_t)) | 59 | if (len > bos / sizeof(gid_t)) |
| 67 | __builtin_trap(); | 60 | __builtin_trap(); |
| 68 | return __getgroups_orig(len, set); | 61 | return __orig_getgroups(len, set); |
| 69 | } | 62 | } |
| 70 | 63 | ||
| 71 | __typeof__(gethostname) __gethostname_orig __asm__(__USER_LABEL_PREFIX__ "gethostname"); | 64 | fortify_fn(gethostname) int gethostname(char *name, size_t len) |
| 72 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 73 | int gethostname(char *name, size_t len) | ||
| 74 | { | 65 | { |
| 75 | size_t bos = __builtin_object_size(name, 0); | 66 | size_t bos = __builtin_object_size(name, 0); |
| 76 | 67 | ||
| 77 | if (len > bos) | 68 | if (len > bos) |
| 78 | __builtin_trap(); | 69 | __builtin_trap(); |
| 79 | return __gethostname_orig(name, len); | 70 | return __orig_gethostname(name, len); |
| 80 | } | 71 | } |
| 81 | 72 | ||
| 82 | __typeof__(getlogin_r) __getlogin_r_orig __asm__(__USER_LABEL_PREFIX__ "getlogin_r"); | 73 | fortify_fn(getlogin_r) int getlogin_r(char *name, size_t len) |
| 83 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 84 | int getlogin_r(char *name, size_t len) | ||
| 85 | { | 74 | { |
| 86 | size_t bos = __builtin_object_size(name, 0); | 75 | size_t bos = __builtin_object_size(name, 0); |
| 87 | 76 | ||
| 88 | if (len > bos) | 77 | if (len > bos) |
| 89 | __builtin_trap(); | 78 | __builtin_trap(); |
| 90 | return __getlogin_r_orig(name, len); | 79 | return __orig_getlogin_r(name, len); |
| 91 | } | 80 | } |
| 92 | 81 | ||
| 93 | __typeof__(pread) __pread_orig __asm__(__USER_LABEL_PREFIX__ "pread"); | 82 | fortify_fn(pread) ssize_t pread(int fd, void *buf, size_t n, off_t offset) |
| 94 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 95 | ssize_t pread(int fd, void *buf, size_t n, off_t offset) | ||
| 96 | { | 83 | { |
| 97 | size_t bos = __builtin_object_size(buf, 0); | 84 | size_t bos = __builtin_object_size(buf, 0); |
| 98 | 85 | ||
| 99 | if (n > bos) | 86 | if (n > bos) |
| 100 | __builtin_trap(); | 87 | __builtin_trap(); |
| 101 | return __pread_orig(fd, buf, n, offset); | 88 | return __orig_pread(fd, buf, n, offset); |
| 102 | } | 89 | } |
| 103 | 90 | ||
| 104 | __typeof__(read) __read_orig __asm__(__USER_LABEL_PREFIX__ "read"); | 91 | fortify_fn(read) ssize_t read(int fd, void *buf, size_t n) |
| 105 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 106 | ssize_t read(int fd, void *buf, size_t n) | ||
| 107 | { | 92 | { |
| 108 | size_t bos = __builtin_object_size(buf, 0); | 93 | size_t bos = __builtin_object_size(buf, 0); |
| 109 | 94 | ||
| 110 | if (n > bos) | 95 | if (n > bos) |
| 111 | __builtin_trap(); | 96 | __builtin_trap(); |
| 112 | return __read_orig(fd, buf, n); | 97 | return __orig_read(fd, buf, n); |
| 113 | } | 98 | } |
| 114 | 99 | ||
| 115 | __typeof__(readlink) __readlink_orig __asm__(__USER_LABEL_PREFIX__ "readlink"); | 100 | fortify_fn(readlink) ssize_t readlink(const char *path, char *buf, size_t n) |
| 116 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 117 | ssize_t readlink(const char *path, char *buf, size_t n) | ||
| 118 | { | 101 | { |
| 119 | size_t bos = __builtin_object_size(buf, 0); | 102 | size_t bos = __builtin_object_size(buf, 0); |
| 120 | 103 | ||
| 121 | if (n > bos) | 104 | if (n > bos) |
| 122 | __builtin_trap(); | 105 | __builtin_trap(); |
| 123 | return __readlink_orig(path, buf, n); | 106 | return __orig_readlink(path, buf, n); |
| 124 | } | 107 | } |
| 125 | 108 | ||
| 126 | __typeof__(readlinkat) __readlinkat_orig __asm__(__USER_LABEL_PREFIX__ "readlinkat"); | 109 | fortify_fn(readlinkat) ssize_t readlinkat(int fd, const char *path, char *buf, size_t n) |
| 127 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 128 | ssize_t readlinkat(int fd, const char *path, char *buf, size_t n) | ||
| 129 | { | 110 | { |
| 130 | size_t bos = __builtin_object_size(buf, 0); | 111 | size_t bos = __builtin_object_size(buf, 0); |
| 131 | 112 | ||
| 132 | if (n > bos) | 113 | if (n > bos) |
| 133 | __builtin_trap(); | 114 | __builtin_trap(); |
| 134 | return __readlinkat_orig(fd, path, buf, n); | 115 | return __orig_readlinkat(fd, path, buf, n); |
| 135 | } | 116 | } |
| 136 | 117 | ||
| 137 | __typeof__(ttyname_r) __ttyname_r_orig __asm__(__USER_LABEL_PREFIX__ "ttyname_r"); | 118 | fortify_fn(ttyname_r) int ttyname_r(int fd, char *name, size_t n) |
| 138 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 139 | int ttyname_r(int fd, char *name, size_t n) | ||
| 140 | { | 119 | { |
| 141 | size_t bos = __builtin_object_size(name, 0); | 120 | size_t bos = __builtin_object_size(name, 0); |
| 142 | 121 | ||
| 143 | if (n > bos) | 122 | if (n > bos) |
| 144 | __builtin_trap(); | 123 | __builtin_trap(); |
| 145 | return __ttyname_r_orig(fd, name, n); | 124 | return __orig_ttyname_r(fd, name, n); |
| 146 | } | 125 | } |
| 147 | 126 | ||
| 148 | __typeof__(write) __write_orig __asm__(__USER_LABEL_PREFIX__ "write"); | 127 | fortify_fn(write) ssize_t write(int fd, const void *buf, size_t n) |
| 149 | extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__)) | ||
| 150 | ssize_t write(int fd, const void *buf, size_t n) | ||
| 151 | { | 128 | { |
| 152 | size_t bos = __builtin_object_size(buf, 0); | 129 | size_t bos = __builtin_object_size(buf, 0); |
| 153 | 130 | ||
| 154 | if (n > bos) | 131 | if (n > bos) |
| 155 | __builtin_trap(); | 132 | __builtin_trap(); |
| 156 | return __write_orig(fd, buf, n); | 133 | return __orig_write(fd, buf, n); |
| 157 | } | 134 | } |
| 158 | 135 | ||
| 159 | #ifdef __cplusplus | 136 | #ifdef __cplusplus |
