diff options
| author | sin | 2015-02-28 12:00:25 +0000 |
|---|---|---|
| committer | sin | 2015-02-28 12:00:25 +0000 |
| commit | 195fffa420525a53ecd72c6d49c8660630e97359 (patch) | |
| tree | 0a63193a887b194bc47f593a722ace41270308c5 /include | |
| parent | 60a707681655d249af66cec6786a6fad8337b49c (diff) | |
Add getgroups() check
Since getgroups() will never write more than NGROUPS_MAX entries
we might as well cap len to that value.
The following should probably not trap the program:
gid_t set[NGROUPS_MAX];
getgroups(NGROUPS_MAX + 1, set);
Diffstat (limited to 'include')
| -rw-r--r-- | include/unistd.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h index b193a7f..3c5eec9 100644 --- a/include/unistd.h +++ b/include/unistd.h | |||
| @@ -42,6 +42,17 @@ __fortify_getdomainname(char *name, size_t len) | |||
| 42 | 42 | ||
| 43 | static inline __attribute__ ((always_inline)) | 43 | static inline __attribute__ ((always_inline)) |
| 44 | int | 44 | int |
| 45 | __fortify_getgroups(int len, gid_t *set) | ||
| 46 | { | ||
| 47 | size_t bos = __builtin_object_size(set, 0); | ||
| 48 | |||
| 49 | if (bos != -1 && len > bos / sizeof(gid_t)) | ||
| 50 | __builtin_trap(); | ||
| 51 | return getgroups(len, set); | ||
| 52 | } | ||
| 53 | |||
| 54 | static inline __attribute__ ((always_inline)) | ||
| 55 | int | ||
| 45 | __fortify_gethostname(char *name, size_t len) | 56 | __fortify_gethostname(char *name, size_t len) |
| 46 | { | 57 | { |
| 47 | size_t bos = __builtin_object_size(name, 0); | 58 | size_t bos = __builtin_object_size(name, 0); |
| @@ -105,6 +116,8 @@ __fortify_write(int fd, const void *buf, size_t n) | |||
| 105 | #define getdomainname(name, len) __fortify_getdomainname(name, len) | 116 | #define getdomainname(name, len) __fortify_getdomainname(name, len) |
| 106 | #endif | 117 | #endif |
| 107 | 118 | ||
| 119 | #undef getgroups | ||
| 120 | #define getgroups(len, set) __fortify_getgroups(len, set) | ||
| 108 | #undef gethostname | 121 | #undef gethostname |
| 109 | #define gethostname(name, len) __fortify_gethostname(name, len) | 122 | #define gethostname(name, len) __fortify_gethostname(name, len) |
| 110 | #undef getlogin_r | 123 | #undef getlogin_r |
