JianyuWang0623 opened a new pull request, #20613:
URL: https://github.com/apache/nuttx/pull/20613
## Summary
`tcp_selectport()` unconditionally initializes the random TCP port base
(`NET_PORT_RANDOM_INIT()` → `arc4random_buf()` → `getrandom()` →
`open("/dev/urandom")`) on first call, even when the caller supplies a fixed,
non-zero `portno` and never needs a randomly-assigned port. On a
stack-constrained caller binding a fixed port early in boot, this unnecessary
deep call chain can overflow the stack.
This change limits the random-port-base initialization to the path that
actually needs it: `portno == 0` (automatic port allocation). Fixed-port binds
now skip it entirely. The initialization call site is unchanged otherwise
(still runs before `tcp_conn_list_lock()`).
## Impact
- `net/tcp` — `tcp_selectport()` only.
- No behavior change for `portno == 0` callers.
- Fixed-port (`portno != 0`) callers no longer invoke
`NET_PORT_RANDOM_INIT()`, reducing stack depth on that path.
## Testing
- `./tools/checkpatch.sh -g HEAD` → all checks pass.
--
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]