Skip to content

system/nxrecorder: Fix null pointer dereference in argument parsing#3435

Open
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:nxrecorder_null_ptr
Open

system/nxrecorder: Fix null pointer dereference in argument parsing#3435
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:nxrecorder_null_ptr

Conversation

@JianyuWang0623
Copy link
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

system/nxrecorder/nxrecorder_main.c contains a command parsing loop that trims leading spaces from the arg string returned by strtok_r(). When a command takes no arguments (e.g., q, quit, stop), strtok_r() returns NULL for arg. The original loop while (*arg == ' ') unconditionally dereferenced arg without a null check, causing undefined behavior — manifesting as a system hang on ESP32-S3.

The fix adds a null guard before the dereference:

- while (*arg == ' ')
+ while (arg && *arg == ' ')

Impact

  • Fixes a null pointer dereference in nxrecorder_main.c argument parsing.
  • Affects any target running nxrecorder where no-argument commands (q, quit, stop, etc.) are used interactively.
  • No API, ABI, or configuration changes. No new dependencies introduced.
  • Improves stability and prevents undefined behavior / system hang when issuing argument-less commands.

Testing

  • Host: Linux x86_64
  • Target: ESP32-S3 (lckfb-szpi-esp32s3:nsh or equivalent config)
  • Verified that issuing the quit (and q, stop) command in nxrecorder no longer causes a system hang.
  • Before fix: entering quit with no arguments caused a null pointer dereference and the system hung.
  • After fix: quit exits cleanly as expected.

When a command has no arguments (e.g., 'q', 'quit', 'stop'), the strtok_r()
function returns NULL for the arg parameter. The argument trimming loop was
dereferencing this NULL pointer without checking, causing undefined behavior
and system hang on ESP32-S3.

This commit adds a null check before dereferencing the arg pointer in the
leading space trimming loop.

Tested on ESP32-S3 (lckfb-szpi-esp32s3) - quit command now works correctly.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant