hujun260 opened a new pull request, #17985:
URL: https://github.com/apache/nuttx/pull/17985
## Summary
Fix null pointer dereference in fork operation when setting up address
environments. The addrenv_join() function accesses the child task's group
pointer (child->group), which is initialized by group_initialize(). By moving
addrenv_join() to occur after group_initialize(), the code ensures child->group
is properly set before it is accessed, eliminating the null pointer dereference.
## Changes
- **sched/task/task_fork.c**:
- Move address environment join block in nxtask_setup_fork() from before
group_initialize() to after it
- Relocate addrenv_join() call and its error handling to execute after
group_initialize()
- Maintain all other fork operation sequencing and error handling
## Benefits & Technical Details
- **Null pointer safety**: child->group is now guaranteed to be initialized
before addrenv_join() accesses it
- **Correct sequencing**: Task group initialization must precede address
environment operations
- **Error handling**: All error paths correctly handled with existing
cleanup logic
- **Fork correctness**: Child task inherits parent's address environment
with proper initialization
## Testing
- Verified fork operations complete without null pointer dereference
- Confirmed child task group is properly initialized before address
environment join
- Tested fork with CONFIG_ARCH_ADDRENV enabled and disabled
- Validated child task inherits correct address environment from parent
- Confirmed no regression in fork functionality or child task creation
## Impact
- **Correctness**: Fixes crash in fork when CONFIG_ARCH_ADDRENV is enabled
- **Compatibility**: Fully backward compatible, no API changes
- **Configuration**: Particularly important for builds with
CONFIG_ARCH_ADDRENV
- **Scope**: Affects fork-based task creation with address environment
support
--
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]