Support gcc FORTIFY_SOURCE features for nuttx libc

This function will use gcc's function
__builtin_dynamic_object_size and __builtin_object_size

Its function is to obtain the size of the object through compilation,
so as to judge whether there are out-of-bounds operations in commonly used functions.
It should be noted that the option -O2 and above is required to enable this function

Signed-off-by: anjiahao <1090959677@qq.com>
This commit is contained in:
anjiahao
2023-05-23 06:46:19 +08:00
committed by Xiang Xiao
parent 880d78f903
commit d5981375a6
10 changed files with 483 additions and 0 deletions
+23
View File
@@ -291,6 +291,29 @@ FAR const char *getprogname(void);
int __cxa_atexit(CODE void (*func)(FAR void *), FAR void *arg,
FAR void *dso_handle);
#if CONFIG_FORTIFY_SOURCE > 0
fortify_function(realpath) FAR char *realpath(FAR const char *path,
FAR char *resolved)
{
FAR char *ret = __real_realpath(path, resolved);
if (ret != NULL && resolved != NULL)
{
size_t len = 1;
FAR char *p;
p = ret;
while (*p++ != '\0')
{
len++;
}
fortify_assert(len <= fortify_size(resolved, 0));
}
return ret;
}
#endif
#undef EXTERN
#if defined(__cplusplus)
}