prctl: Replace strncpy with strlcpy for safety
strlcpy ensure the destination is NUL-terminated, and also fix warning: ```c task/task_prctl.c:138:15: warning: 'strncpy' output may be truncated copying 30 bytes from a string of length 31 [-Wstringop-truncation] 138 | strncpy(name, tcb->name, CONFIG_TASK_NAME_SIZE - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
456aaa8c1c
commit
1ba443aab2
@ -126,7 +126,7 @@ int prctl(int option, ...)
|
||||
* necessary.
|
||||
*/
|
||||
|
||||
strncpy(tcb->name, name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(tcb->name, name, sizeof(tcb->name));
|
||||
tcb->name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
}
|
||||
else
|
||||
@ -135,7 +135,7 @@ int prctl(int option, ...)
|
||||
* necessary.
|
||||
*/
|
||||
|
||||
strncpy(name, tcb->name, CONFIG_TASK_NAME_SIZE - 1);
|
||||
strlcpy(name, tcb->name, sizeof(tcb->name));
|
||||
name[CONFIG_TASK_NAME_SIZE - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user