nshlib: Fix memory corruption in nsh_parse.c

Summary:
- Fix memory corruption when pthread_create() failed in nsh_execute()

Impact:

- nsh builtin command execution in background with errors

Testing:

- Tested with hifive1-revb:nsh
- Set CONFIG_MAX_TASKS=4
- Run 'sleep 1000 &' in 3 times will cause pthread_create error
- Run free, ps command

Reported-by: Yoshinori Sugino <ysgn0101@gmail.com>
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa 2020-08-11 16:15:16 +09:00 committed by Alin Jerpelea
parent a6674b6edc
commit 7f48576218

View File

@ -654,8 +654,10 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "sched_getparm",
NSH_ERRNO);
/* NOTE: bkgvtbl is released in nsh_relaseargs() */
nsh_releaseargs(args);
nsh_release(bkgvtbl);
goto errout;
}
@ -699,8 +701,10 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "pthread_create",
NSH_ERRNO_OF(ret));
/* NOTE: bkgvtbl is released in nsh_relaseargs() */
nsh_releaseargs(args);
nsh_release(bkgvtbl);
goto errout;
}