[kernel] 修正复制name字段时潜在的内存踩踏问题

This commit is contained in:
Meco Man 2022-11-08 22:51:36 -05:00 committed by Man, Jianting (Meco)
parent a6151716b2
commit 2d17fe736f
1 changed files with 2 additions and 1 deletions

View File

@ -366,7 +366,8 @@ void rt_object_init(struct rt_object *object,
/* set object type to static */ /* set object type to static */
object->type = type | RT_Object_Class_Static; object->type = type | RT_Object_Class_Static;
/* copy name */ /* copy name */
rt_strncpy(object->name, name, RT_NAME_MAX); rt_strncpy(object->name, name, RT_NAME_MAX - 1);
object->name[RT_NAME_MAX - 1] = '\0';
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object)); RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));