fortify-headers/include/stdlib.h

44 lines
933 B
C
Raw Normal View History

#ifndef _FORTIFY_STDLIB_H
#define _FORTIFY_STDLIB_H
2015-02-24 19:04:02 +00:00
#include_next <stdlib.h>
2015-02-28 16:11:32 +00:00
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
2015-02-24 19:04:02 +00:00
#include_next <limits.h>
#endif
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
2015-03-13 23:09:15 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2015-03-11 09:26:11 +00:00
2015-02-28 16:11:32 +00:00
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef realpath
__typeof__(realpath) __realpath_orig __asm__(__USER_LABEL_PREFIX__ "realpath");
2015-03-14 09:38:11 +00:00
extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
char *realpath(const char *path, char *resolved)
2015-02-24 19:04:02 +00:00
{
size_t bos;
if (resolved) {
#ifndef PATH_MAX
2015-05-07 17:04:01 +00:00
#error PATH_MAX unset. A fortified realpath will not work.
#else
2015-02-24 19:04:02 +00:00
bos = __builtin_object_size(resolved, 0);
if (PATH_MAX > bos)
__builtin_trap();
#endif
2015-02-24 19:04:02 +00:00
}
return __realpath_orig(path, resolved);
2015-02-24 19:04:02 +00:00
}
#endif
2015-03-13 23:09:15 +00:00
#ifdef __cplusplus
}
2015-03-11 09:26:11 +00:00
#endif
2015-02-24 19:04:02 +00:00
#endif
#endif