Page MenuHomeFreeBSD

unix: let unp_connect_peer() own the listener address buffer
Needs RevisionPublic

Authored by inquire_JohnEricson.me on Mon, Aug 10, 8:45 PM.
Tags
None
Referenced Files
F167317848: D58769.id183825.diff
Thu, Aug 20, 9:06 PM
Unknown Object (File)
Wed, Aug 19, 2:41 PM
Unknown Object (File)
Wed, Aug 19, 5:18 AM
Unknown Object (File)
Tue, Aug 18, 2:00 PM
Unknown Object (File)
Tue, Aug 18, 1:43 PM
Unknown Object (File)
Tue, Aug 18, 12:51 PM
Unknown Object (File)
Mon, Aug 17, 3:00 PM
Unknown Object (File)
Sat, Aug 15, 2:13 AM
Subscribers

Details

Reviewers
markj
glebius
Summary

The buffer that receives a listener's address on behalf of a newly
accepted socket was allocated by unp_connectat() and passed down as
struct sockaddr **sap, to be consumed -- signalled by storing NULL
through it -- or else freed by the caller. Only unp_connect_peer()
ever looks at it.

The intent was fine enough -- there is some locking around the place
where the buffer is actually written to, so it must be allocated in
advance. However, the malloc was simply occurring way too far in
advance for no reason, and especially after the little functions were
recently split out, this resulted in needless spaghetti.

Allocate it in the function that needs it instead, avoiding an extra
parameter and making it a purely local resource allocated and freed
within the same function.

No functional change intended.

Signed-off-by: John Ericson <John.Ericson@Obsidian.Systems>
Assisted-by: Claude Code (Claude Opus 5)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75502
Build 72385: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Tue, Aug 18, 1:09 PM
glebius requested changes to this revision.Tue, Aug 18, 5:33 PM

Good find! Few improvements suggested.

sys/kern/uipc_usrreq.c
3218

sa declaration can be moved inside this block with proper type.

3236–3240
  1. free sa right here if not needed
  2. while here migrate from bcopy to memcpy
  3. cast is no longer needed as sa is properly typed
This revision now requires changes to proceed.Tue, Aug 18, 5:33 PM