This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 9b5103530 nshlib/nsh_fscmds: Fix potential NULL pointer dereferences
9b5103530 is described below
commit 9b51035300f15afde063c0cc5413d8ce2b728bf0
Author: hanzhijian <[email protected]>
AuthorDate: Tue Jun 30 16:17:50 2026 +0800
nshlib/nsh_fscmds: Fix potential NULL pointer dereferences
Fix two potential NULL pointer dereferences in nsh_fscmds.c:
1. fdinfo_callback: asprintf() failure left filepath potentially
NULL, which was then passed to nsh_catfile(). Add early return
on asprintf failure.
2. cmd_cat: malloc(BUFSIZ) for stdin reading was used without
checking the return value. Add NULL check with -ENOMEM return.
Also fix a typo in error message: 'nsh_catfaile' -> 'nsh_catfile'.
Signed-off-by: hanzhijian <[email protected]>
---
nshlib/nsh_fscmds.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index 952556ce1..a3423494c 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -753,13 +753,14 @@ static int fdinfo_callback(FAR struct nsh_vtbl_s *vtbl,
if (ret < 0)
{
nsh_error(vtbl, g_fmtcmdfailed, "fdinfo", "asprintf", NSH_ERRNO);
+ return ret;
}
nsh_output(vtbl, "\npid:%s", entryp->d_name);
ret = nsh_catfile(vtbl, "fdinfo", filepath);
if (ret < 0)
{
- nsh_error(vtbl, g_fmtcmdfailed, "fdinfo", "nsh_catfaile", NSH_ERRNO);
+ nsh_error(vtbl, g_fmtcmdfailed, "fdinfo", "nsh_catfile", NSH_ERRNO);
}
free(filepath);
@@ -871,6 +872,10 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
if (argc == 1)
{
char *buf = malloc(BUFSIZ);
+ if (buf == NULL)
+ {
+ return -ENOMEM;
+ }
/* Dump from input */