mirror of
https://github.com/apache/nuttx.git
synced 2026-05-25 01:39:44 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user