Got use-after-free warning under GCC 12 with `-O3` option, and I found
that `nsh_strcat` may realloc `ptr`, then `cmdline` may point to invalid
memory.
Let `cmdline` point to the reallocated `ptr` may solve the problem.
Tested by `alias ll='ls -l'` and `ll /` on sim.
GCC output:
CC: binfmt_unloadmodule.c In function 'nsh_aliasexpand',
inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1196:23: error: pointer 'ptr' used after 'realloc' [-Werror=use-after-free]
1196 | ptr = cmdline + len;
| ~~~~~~~~^~~~~~~~~~~~~~~
In function 'nsh_strcat',
inlined from 'nsh_aliasexpand' at nsh_parse.c:1190:21,
inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1100:27: note: call to 'realloc' here
1100 | argument = (FAR char *)realloc(s1, allocsize);
| ^~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
Fix error: implicit declaration of function 'nsh_foreach_direntry' [-Werror=implicit-function-declaration] on file nsh_fscmds on some compiler versions.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
text data bss dec hex filename
398953 27088 4128 430169 69059 nuttx /* before */
389241 27072 4128 420441 66a59 nuttx /* after */
-9712 -16
Signed-off-by: chao an <anchao@xiaomi.com>
Add missing FAR and CODE to pointers
Remove FAR for non-pointer variables
Remove extra spaces and align the parameters
Add do {} while(0) wrapper in macro
Use nitems to calculate number of elements in arrays
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
Test on sim/nsh (CONFIG_NSH_DISABLE_HELP=y):
text data bss dec hex filename
393746 26824 4000 424570 67a7a nuttx /* before */
391858 26440 4000 422298 6719a nuttx /* after */
-1888 -384
Signed-off-by: chao an <anchao@xiaomi.com>
When rm -r is passed with no address specified, it will automatically recursively unlink all files under the root path ('/') until unlinking to the mounted folder causes the unlink to fail. In this change, rm -r without a specified path will prompt for missing arguments
Current implementation is broken, in this patch ECHO is
disabled by termios.
This patch works with https://github.com/apache/nuttx/pull/8950
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
The logic that handles back-quotes was faulty, i.e. example command
set FOO `ls -l` would be split into two tokens as follows:
- set FOO `ls
- -l`
This results in nsh: `: no matching ` error, this fixes that issue.
This adds support for more complex alias handling, such as:
$ alias ls='ls -l'
Previously such an alias was not split into the command verb and the
argument correctly, instead the full alias string was handled as the
verb, which obviously fails.
This commit fixes this by expanding the alias, checking whether it has
arguments and if so, it merges the expanded alias + the old command line
together, resulting in a completely new command line.
Example (assuming the alias above has been created):
$ ls /bin
Results in a new command line: "ls -l /bin" which is then parsed and
executed.
switchboot <image path>
Switch to the updated or specified boot system. This command depends on
hardware support CONFIG_BOARDCTL_SWITCH_BOOT. `<image path>` point to a
partion or file which contain the firmware to boot.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
boot [<image path> [<header size>]]
Boot a new firmware image. This command depends on hardware support
CONFIG_BOARDCTL_BOOT_IMAGE. <image path> may point to a partion or file
which contain the firmware to boot. The optional, numeric argument
<header size> may be useful for skipping metadata information preprended
to the firmware image.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Summary:
- I noticed that the ps command shows the wrong format due to
recent changes on sigmask length from 32bits to 64bits
- This commit fixes this issue
Impact:
- None
Testing:
- Tested with sabre-6quad:smp on qemu-7.1
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
A resulting word that is identified to be the command name word of a
simple command shall be examined to determine whether it is an unquoted,
valid alias name.
The keyword here being "a simple command", arguments are not subject to
expansion.
This adds support for string aliases into nsh. There are some nuances that
are not handled correctly yet:
- Reserved words can be overloaded, which is a clear POSIX violation
The parser is modified to detect, handle and remove quotes from the
command string. Whatever is inside the quotes is treated as a string
literal. If no matching end quote is found, the terminal prints out
and error.
If the code only change c_oflag, c_iflag and c_lflag, not c_cflag in termios.
Follow up the change from kernel: https://github.com/apache/nuttx/pull/8843
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
nsh_vars.c: In function 'nsh_setvar':
nsh_vars.c:285:3: error: incompatible implicit declaration of built-in function 'sprintf' [-Werror]
285 | sprintf(pair, "%s=%s", name, value);
Introduced by https://github.com/apache/nuttx-apps/pull/1610,
internal line buffer should have more bytes for tab before newline and '\0'.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>