Zepp-Hanzj opened a new pull request, #3575:
URL: https://github.com/apache/nuttx-apps/pull/3575

   ## Summary
   
   Fix two potential NULL pointer dereferences in `nshlib/nsh_fscmds.c`.
   
   ## Changes
   
   ### 1. `fdinfo_callback` — NULL deref after asprintf failure
   
   When `asprintf()` fails (returns < 0), `filepath` may be NULL. The code 
logged an error but did **not** return — it fell through and passed the NULL 
`filepath` to `nsh_catfile()`, causing a NULL pointer dereference.
   
   **Fix**: Add `return ret;` after the asprintf error path.
   
   Also fixed a typo in the error message: `"nsh_catfaile"` → `"nsh_catfile"`.
   
   ### 2. `cmd_cat` — NULL deref after malloc failure
   
   When `argc == 1` (reading from stdin), `malloc(BUFSIZ)` was called but the 
return value was never checked. If malloc fails, `buf` is NULL and 
`nsh_read(vtbl, buf, BUFSIZ)` would dereference it.
   
   **Fix**: Add `if (buf == NULL) return -ENOMEM;` after the malloc call.
   
   ## Verification
   
   Built and tested on `sim:nsh` configuration:
   
   ```
   nsh> cat /data/hello.txt
   hello
   
   nsh> cat /etc/group
   root:*:0:root,admin
   
   nsh> fdinfo 0
   FD  OFLAGS  TYPE POS       PATH
   0   3       1    0         /dev/console
   1   3       1    0         /dev/console
   2   3       1    0         /dev/console
   
   nsh> fdinfo 1
   FD  OFLAGS  TYPE POS       PATH
   0   3       1    0         /dev/console
   1   3       1    0         /dev/console
   2   3       1    0         /dev/console
   
   nsh> ls -l /data
    -rw-r--r--         152 .version
    -rw-r--r--        1883 .config.backup
    drwxr-xr-x        4096 binfmt/
   
   nsh> help
       .           cmp         false       mkfifo      readlink    time
       [           dirname     fdinfo      mkrd        rm          true
   ```
   
   Signed-off-by: hanzhijian <[email protected]>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to