diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-12 18:49:58 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-12 18:49:58 -0600 |
commit | 8a4723fb73f37f425cb8c6543f1c5e2b61803924 (patch) | |
tree | 819aded46cf249bd1a47136d7050826db05bfa4e /nuttx/sched | |
parent | 6c2629fcb339d7878dbe6b58a792df7de824f32a (diff) | |
download | nuttx-8a4723fb73f37f425cb8c6543f1c5e2b61803924.tar.gz nuttx-8a4723fb73f37f425cb8c6543f1c5e2b61803924.tar.bz2 nuttx-8a4723fb73f37f425cb8c6543f1c5e2b61803924.zip |
task_setup() no longer depends on CONFIG_MAX_TASK_ARGS
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/task/task_setup.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/nuttx/sched/task/task_setup.c b/nuttx/sched/task/task_setup.c index bed71707b..7320cf19d 100644 --- a/nuttx/sched/task/task_setup.c +++ b/nuttx/sched/task/task_setup.c @@ -56,6 +56,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* This is an artificial limit to detect error conditions where an argv[] + * list is not properly terminated. + */ + +#define MAX_STACK_ARGS 256 /**************************************************************************** * Private Type Declarations @@ -481,18 +486,24 @@ static inline int task_stackargsetup(FAR struct task_tcb_s *tcb, argc = 0; if (argv) { - for (; argc <= CONFIG_MAX_TASK_ARGS; argc++) - { - /* A NULL argument terminates the list */ - - if (!argv[argc]) - { - break; - } + /* A NULL argument terminates the list */ + while (argv[argc]) + { /* Add the size of this argument (with NUL terminator) */ strtablen += (strlen(argv[argc]) + 1); + + /* Increment the number of args. Here is a sanity check to + * prevent running away with an unterminated argv[] list. + * MAX_STACK_ARGS should be sufficiently large that this never + * happens in normal usage. + */ + + if (++argc > MAX_STACK_ARGS) + { + return -E2BIG; + } } } |