- Handle nsh_filecat returning NULL on failure
- Background and redirect must be restored after an empty line
- Output redirection should be removed from argv like background
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>
Add some comments to nsh_parse.c emphasizing the reason that things are done in the order that they are. Perhaps such comments will avoid similar breakage in the future.
commit 9a28ccf836
Author: chao.an <anchao@xiaomi.com>
Date: Fri Feb 21 09:54:47 2020 +0800
nsh/parse: try the builtin configuration first
In the case of enable the BUILTIN_APPS/FILE_APPS at the same time,
try the builtin list first to ensure that the relevant configuration
(stacksize, priority) can be set normally.
This commit breaks the feature because it changes the order to that the built-in application is tried first. Hence, the version on the file system will never replace the built-in version.
That commit must be reverted in order to restore the correct functionality.
Revert "nsh/parse: try the builtin configuration first"
This reverts commit 9a28ccf836.
In the case of enable the BUILTIN_APPS/FILE_APPS at the same time, try the builtin list first to ensure that the relevant configuration(stacksize, priority) can be set normally.
1.Remove void cast for function because many place ignore the returned value witout cast
2.Replace void cast for variable with UNUSED macro
Change-Id: Ie644129a563244a6397036789c4c3ea83c4e9b09
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Per SUZUKI Y <NBG03015@nifty.ne.jp>, changing:
- return (FAR char *)g_nullstring;
+ return "";
causes a bad return value because "" lies on the stack.
This reverts commit 9defae8af6.
include/ and netutils/: Remove references to CONFIG_DISABLE_SIGNALS. Signals can no longer be disabled.
nshlib/: Remove references to CONFIG_DISABLE_SIGNALS. Signals can no longer be disabled.
system/: Remove references to CONFIG_DISABLE_SIGNALS. Signals can no longer be disabled.
testing/: Remove references to CONFIG_DISABLE_SIGNALS. Signals can no longer be disabled.
examples/: Remove references to CONFIG_DISABLE_SIGNALS. Signals can no longer be disabled.
Test case:
NuttShell (NSH)
nsh> mkrd -s 1024 40
nsh> mkfatfs /dev/ram0
nsh> mount -t vfat /dev/ram0 /tmp
nsh> echo "echo 1 > /dev/null" > /tmp/test.sh
nsh> cat /tmp/test.sh
echo 1 > /dev/null
nsh> sh /tmp/test.sh
...
The nsh prompt doesn't get printed. You can type a couple of commands, but then the system will crash because of bad pointers.
nsh_parse.c: fix 'while' and 'until' loop condition
The loop condition logic was inverted:
while true; do echo "test"; done
would exit immediately, while using 'until' would stay in the loop.
This is the opposite of how it is supposed to work.
The reason is that 'state' was set wrong because 'whilematch' is a bool.
Approved-by: Gregory Nutt <gnutt@nuttx.org>
nshlib/nsh_parse.c: Avoid truncating the strcmp result into a unsigned char variable.
nshlib/nsh_netcmds.c: Check for valid hostip before using it.
nshlib/nsh_ddcmd.c: Fix resouce leak when 'if=' or 'of=' params are repeated in the command line. For example:
dd if=/dev/null if=/dev/zero of=/dev/null or
dd if=/dev/zero of=/dev/zero of=/dev/null