From f05c09fac82907ed0f05adaffe10c3832a245297 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 24 Feb 2015 19:04:02 +0000 Subject: Add realpath() check --- include/stdlib.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/stdlib.h (limited to 'include') diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000..2948b54 --- /dev/null +++ b/include/stdlib.h @@ -0,0 +1,35 @@ +#ifndef FORTIFY_STDLIB_H_ +#define FORTIFY_STDLIB_H_ + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +#include_next +#endif + +#include_next + +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +static inline __attribute__ ((always_inline)) +char * +__fortify_realpath(const char *path, char *resolved) +{ + size_t bos; + + if (resolved) { + bos = __builtin_object_size(resolved, 0); + if (PATH_MAX > bos) + __builtin_trap(); + } + return realpath(path, resolved); +} + +#undef realpath +#define realpath(path, resolved) __fortify_realpath(path, resolved) +#endif + +#endif + +#endif -- cgit v1.3