commit f05c09fac82907ed0f05adaffe10c3832a245297
parent eecef18261cc278fbc13ecbfb4e5bc10762cc794
Author: sin <sin@2f30.org>
Date: Tue, 24 Feb 2015 19:04:02 +0000
Add realpath() check
Diffstat:
1 file changed, 35 insertions(+), 0 deletions(-)
diff --git a/include/stdlib.h 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 <limits.h>
+#endif
+
+#include_next <stdlib.h>
+
+#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