system/nxrecorder: Fix null pointer dereference in argument parsing#3435
Open
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
Open
system/nxrecorder: Fix null pointer dereference in argument parsing#3435JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
system/nxrecorder/nxrecorder_main.ccontains a command parsing loop that trims leading spaces from theargstring returned bystrtok_r(). When a command takes no arguments (e.g.,q,quit,stop),strtok_r()returnsNULLforarg. The original loopwhile (*arg == ' ')unconditionally dereferencedargwithout a null check, causing undefined behavior — manifesting as a system hang on ESP32-S3.The fix adds a null guard before the dereference:
Impact
nxrecorder_main.cargument parsing.nxrecorderwhere no-argument commands (q,quit,stop, etc.) are used interactively.Testing
lckfb-szpi-esp32s3:nshor equivalent config)quit(andq,stop) command innxrecorderno longer causes a system hang.quitwith no arguments caused a null pointer dereference and the system hung.quitexits cleanly as expected.