summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorsin2015-02-23 10:45:20 +0000
committersin2015-02-23 10:45:20 +0000
commit9a77136c5914f6be50df195dac0f99424252a297 (patch)
treee7ecb988bf3117110f71f18f57a6c1ee8a073e33 /include
parentc1734bf20671b1c45d6964e34b85d954e2620b88 (diff)
Add gethostname() checks
Diffstat (limited to 'include')
-rw-r--r--include/unistd.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index 0e28b78..bffccf7 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -37,6 +37,21 @@ __fortify_getcwd(char *buf, size_t len)
37 return getcwd(buf, len); 37 return getcwd(buf, len);
38} 38}
39 39
40__errordecl(__gethostname_error, "gethostname: buffer overflow detected");
41static inline __attribute__ ((always_inline))
42int
43__fortify_gethostname(char *name, size_t len)
44{
45 size_t bos = __builtin_object_size(name, 0);
46
47 if (__builtin_constant_p(len) && len > bos)
48 __gethostname_error();
49
50 if (len > bos)
51 __builtin_trap();
52 return gethostname(name, len);
53}
54
40__errordecl(__pread_error, "pread: buffer overflow detected"); 55__errordecl(__pread_error, "pread: buffer overflow detected");
41static inline __attribute__ ((always_inline)) 56static inline __attribute__ ((always_inline))
42ssize_t 57ssize_t
@@ -71,6 +86,8 @@ __fortify_read(int fd, void *buf, size_t n)
71#define confstr(name, buf, len) __fortify_confstr(name, buf, len) 86#define confstr(name, buf, len) __fortify_confstr(name, buf, len)
72#undef getcwd 87#undef getcwd
73#define getcwd(buf, len) __fortify_getcwd(buf, len) 88#define getcwd(buf, len) __fortify_getcwd(buf, len)
89#undef gethostname
90#define gethostname(name, len) __fortify_gethostname(name, len)
74#undef pread 91#undef pread
75#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) 92#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset)
76#undef read 93#undef read