strncpy will not copy the terminating \0 into the destination if the source is larger than the size of the destination. Ensure that the last byte is always zero and let strncpy only copy CONFIG_TASK_NAME_SIZE bytes. The issue of unterminated names can be observed in ps when creating a pthread while CONFIG_TASK_NAME_SIZE is set to 8.
This commit is contained in:
parent
8e4f7230f9
commit
937f9f23f1
|
@ -536,7 +536,7 @@ struct tcb_s
|
|||
struct xcptcontext xcp; /* Interrupt register save area */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
char name[CONFIG_TASK_NAME_SIZE]; /* Task name */
|
||||
char name[CONFIG_TASK_NAME_SIZE+1]; /* Task name (with NUL terminator) */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -297,11 +297,13 @@ config RR_INTERVAL
|
|||
|
||||
config TASK_NAME_SIZE
|
||||
int "Maximum task name size"
|
||||
default 32
|
||||
default 31
|
||||
---help---
|
||||
Spcifies that maximum size of a task name to save in the TCB.
|
||||
Useful if scheduler instrumentation is selected. Set to zero to
|
||||
disable.
|
||||
disable. Excludes the NUL terminator; the actual allocated size
|
||||
willl be TASK_NAME_SIZE + 1. The default of 31 then results in
|
||||
a align-able 32-byte allocation.::
|
||||
|
||||
config MAX_TASKS
|
||||
int "Max number of tasks"
|
||||
|
|
|
@ -307,7 +307,8 @@ void os_start(void)
|
|||
/* Set the IDLE task name */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(g_idletcb.cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE-1);
|
||||
strncpy(g_idletcb.cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE);
|
||||
g_idletcb.cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
#endif /* CONFIG_TASK_NAME_SIZE */
|
||||
|
||||
/* Configure the task name in the argument list. The IDLE task does
|
||||
|
|
|
@ -115,6 +115,7 @@ static inline void pthread_argsetup(FAR struct pthread_tcb_s *tcb, pthread_addr_
|
|||
/* Copy the pthread name into the TCB */
|
||||
|
||||
strncpy(tcb->cmn.name, g_pthreadname, CONFIG_TASK_NAME_SIZE);
|
||||
tcb->cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
#endif /* CONFIG_TASK_NAME_SIZE */
|
||||
|
||||
/* For pthreads, args are strictly pass-by-value; that actual
|
||||
|
|
|
@ -133,9 +133,10 @@ int prctl(int option, ...)
|
|||
|
||||
if (option == PR_SET_NAME)
|
||||
{
|
||||
/* tcb->name may not be null-terminated */
|
||||
/* Ensure that tcb->name will be null-terminated, truncating if necessary */
|
||||
|
||||
strncpy(tcb->name, name, CONFIG_TASK_NAME_SIZE);
|
||||
tcb->name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -426,6 +426,7 @@ static void task_namesetup(FAR struct task_tcb_s *tcb, FAR const char *name)
|
|||
/* Copy the name into the TCB */
|
||||
|
||||
strncpy(tcb->cmn.name, name, CONFIG_TASK_NAME_SIZE);
|
||||
tcb->cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
}
|
||||
#else
|
||||
# define task_namesetup(t,n)
|
||||
|
|
Loading…
Reference in New Issue