Page MenuHomeFreeBSD

D58769.1795327892.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D58769.1795327892.diff

diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -293,7 +293,7 @@
static int unp_connectat(int, struct socket *, const char *, int,
struct thread *, struct socket **);
static int unp_connect_peer(struct socket *, struct unpcb *,
- struct sockaddr **, struct thread *, bool);
+ struct thread *, bool);
static int unp_resolve_peer(struct thread *, int, const char *,
struct socket **);
static int unp_vnode_peer(struct vnode *, struct thread *,
@@ -2959,9 +2959,7 @@
struct socket *so2;
struct unpcb *unp;
char buf[SOCK_MAXADDRLEN];
- struct sockaddr *sa;
int error;
- bool connreq;
CURVNET_ASSERT_SET();
@@ -3005,16 +3003,10 @@
unp->unp_flags |= UNP_CONNECTING;
UNP_PCB_UNLOCK(unp);
- connreq = (so->so_proto->pr_flags & PR_CONNREQUIRED) != 0;
- if (connreq)
- sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
- else
- sa = NULL;
-
error = unp_resolve_peer(td, fd, buf, &so2);
if (error != 0)
goto out;
- error = unp_connect_peer(so, sotounpcb(so2), &sa, td,
+ error = unp_connect_peer(so, sotounpcb(so2), td,
referenced_peerp != NULL);
/* Transfer the reference; the caller releases it after unlocking. */
if (error == 0 && referenced_peerp != NULL)
@@ -3022,7 +3014,6 @@
else
sorele(so2);
out:
- free(sa, M_SONAME);
if (__predict_false(error)) {
UNP_PCB_LOCK(unp);
KASSERT((unp->unp_flags & UNP_CONNECTING) != 0,
@@ -3207,13 +3198,11 @@
* caller, which must guarantee its stability by holding a reference on the
* peer socket. Must be called with no locks held.
*
- * For connection-oriented sockets '*sap' points to a buffer to hold the
- * listener's address; it is consumed (set to NULL) if used. On success
- * UNP_CONNECTING is cleared; on error the caller must clear it.
+ * On success UNP_CONNECTING is cleared; on error the caller must clear it.
*/
static int
-unp_connect_peer(struct socket *so, struct unpcb *unp2, struct sockaddr **sap,
- struct thread *td, bool return_locked)
+unp_connect_peer(struct socket *so, struct unpcb *unp2, struct thread *td,
+ bool return_locked)
{
struct socket *so2;
struct unpcb *unp, *unp3, *lunp;
@@ -3229,6 +3218,8 @@
if (so->so_type != so2->so_type)
return (EPROTOTYPE);
if (connreq) {
+ struct sockaddr_un *sa;
+
if (SOLISTENING(so2))
so2 = solisten_clone(so2);
else
@@ -3241,6 +3232,12 @@
}
unp3 = sotounpcb(so2);
+ /*
+ * The listener's address is copied to the new socket under the
+ * PCB locks below, so its storage has to be in hand first.
+ */
+ sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
+
/*
* Hold the listener's lock until the new socket is on its
* queue. uipc_close() marks the listener closed under that
@@ -3250,6 +3247,7 @@
unp_pcb_lock_pair(unp, unp2);
if (__predict_false((unp2->unp_flags & UNP_CLOSED) != 0)) {
unp_pcb_unlock_pair(unp, unp2);
+ free(sa, M_SONAME);
so2->so_listen = NULL;
refcount_init(&so2->so_count, 1);
sorele(so2);
@@ -3262,10 +3260,10 @@
*/
UNP_PCB_LOCK(unp3);
if (unp2->unp_addr != NULL) {
- bcopy(unp2->unp_addr, *sap, unp2->unp_addr->sun_len);
- unp3->unp_addr = (struct sockaddr_un *)*sap;
- *sap = NULL;
- }
+ memcpy(sa, unp2->unp_addr, unp2->unp_addr->sun_len);
+ unp3->unp_addr = sa;
+ } else
+ free(sa, M_SONAME);
unp_copy_peercred(td, unp3, unp, unp2);

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 22, 6:11 AM (10 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41644359
Default Alt Text
D58769.1795327892.diff (3 KB)

Event Timeline