diff --git a/include/stdlib.h b/include/stdlib.h index ef70995..11155cf 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -39,12 +39,10 @@ extern "C" { #undef realpath _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) { - size_t __b = __builtin_object_size(__r, 0); - - if (__r) { #ifndef PATH_MAX #error PATH_MAX unset. A fortified realpath will not work. #else + if (__r && PATH_MAX > __builtin_object_size(__r, 2)) { char __buf[PATH_MAX], *__ret; size_t __l; @@ -52,13 +50,13 @@ _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) if (!__ret) return NULL; __l = __builtin_strlen(__ret) + 1; - if (__l > __b) + if (__l > __builtin_object_size(__r, 0)) __builtin_trap(); __builtin_memcpy(__r, __ret, __l); return __r; -#endif } return __orig_realpath(__p, __r); +#endif } #endif