mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
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:
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user