summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-17 12:24:02 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-17 12:24:02 -0600
commitd9cccec2ed5c71a759f6f2b7198554d6e98fd22c (patch)
tree15ae376a381961d38dc47a348f72d5743075ec40 /nuttx/sched
parent2fa884cbcd0efab5e3f34df978c89415d341a510 (diff)
downloadnuttx-d9cccec2ed5c71a759f6f2b7198554d6e98fd22c.tar.gz
nuttx-d9cccec2ed5c71a759f6f2b7198554d6e98fd22c.tar.bz2
nuttx-d9cccec2ed5c71a759f6f2b7198554d6e98fd22c.zip
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.
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/Kconfig6
-rw-r--r--nuttx/sched/init/os_start.c3
-rw-r--r--nuttx/sched/pthread/pthread_create.c1
-rw-r--r--nuttx/sched/task/task_prctl.c3
-rw-r--r--nuttx/sched/task/task_setup.c1
5 files changed, 10 insertions, 4 deletions
diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig
index 62bc6accb..10b34fe01 100644
--- a/nuttx/sched/Kconfig
+++ b/nuttx/sched/Kconfig
@@ -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"
diff --git a/nuttx/sched/init/os_start.c b/nuttx/sched/init/os_start.c
index 561e79b9b..fcb305180 100644
--- a/nuttx/sched/init/os_start.c
+++ b/nuttx/sched/init/os_start.c
@@ -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
diff --git a/nuttx/sched/pthread/pthread_create.c b/nuttx/sched/pthread/pthread_create.c
index 70c00a447..8cfab5908 100644
--- a/nuttx/sched/pthread/pthread_create.c
+++ b/nuttx/sched/pthread/pthread_create.c
@@ -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
diff --git a/nuttx/sched/task/task_prctl.c b/nuttx/sched/task/task_prctl.c
index b0e00f316..5bbac6b9f 100644
--- a/nuttx/sched/task/task_prctl.c
+++ b/nuttx/sched/task/task_prctl.c
@@ -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
{
diff --git a/nuttx/sched/task/task_setup.c b/nuttx/sched/task/task_setup.c
index 1b838eea3..5474c9126 100644
--- a/nuttx/sched/task/task_setup.c
+++ b/nuttx/sched/task/task_setup.c
@@ -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)