diff options
| author | sin | 2015-07-16 11:45:19 +0100 |
|---|---|---|
| committer | sin | 2015-07-16 11:45:19 +0100 |
| commit | 60dcebb6b812097eb6ca141086c2d8c1875d3347 (patch) | |
| tree | 129af49b666c32f7883d14fcaf7124ebea37846d /include/stdlib.h | |
| parent | edb2ded3af887cd0a206c0f00e20118d58a7775c (diff) | |
Only crash on overflow for realpath()
Diffstat (limited to '')
| -rw-r--r-- | include/stdlib.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/include/stdlib.h b/include/stdlib.h index f89341f..26c7e44 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -35,15 +35,23 @@ extern "C" { | |||
| 35 | #undef realpath | 35 | #undef realpath |
| 36 | _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) | 36 | _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) |
| 37 | { | 37 | { |
| 38 | size_t __b; | 38 | size_t __b = __builtin_object_size(__r, 0); |
| 39 | 39 | ||
| 40 | if (__r) { | 40 | if (__r) { |
| 41 | #ifndef PATH_MAX | 41 | #ifndef PATH_MAX |
| 42 | #error PATH_MAX unset. A fortified realpath will not work. | 42 | #error PATH_MAX unset. A fortified realpath will not work. |
| 43 | #else | 43 | #else |
| 44 | __b = __builtin_object_size(__r, 0); | 44 | char __buf[PATH_MAX], *__ret; |
| 45 | if (PATH_MAX > __b) | 45 | size_t __l; |
| 46 | |||
| 47 | __ret = __orig_realpath(__p, __buf); | ||
| 48 | if (!__ret) | ||
| 49 | return NULL; | ||
| 50 | __l = __builtin_strlen(__ret) + 1; | ||
| 51 | if (__l > __b) | ||
| 46 | __builtin_trap(); | 52 | __builtin_trap(); |
| 53 | __builtin_memcpy(__r, __ret, __l); | ||
| 54 | return __r; | ||
| 47 | #endif | 55 | #endif |
| 48 | } | 56 | } |
| 49 | return __orig_realpath(__p, __r); | 57 | return __orig_realpath(__p, __r); |
