goto out;
}
-
/*
* At this point we know that there is at least one connection
* ready to be accepted. Remove it from the queue prior to
lck_mtx_assert(mutex_held, LCK_MTX_ASSERT_OWNED);
so = TAILQ_FIRST(&head->so_comp);
TAILQ_REMOVE(&head->so_comp, so, so_list);
+ so->so_head = NULL;
+ so->so_state &= ~SS_COMP;
head->so_qlen--;
/* unlock head to avoid deadlock with select, keep a ref on head */
socket_unlock(head, 0);
*/
if ((error = mac_socket_check_accepted(kauth_cred_get(), so)) != 0) {
socket_lock(so, 1);
- so->so_state &= ~(SS_NOFDREF | SS_COMP);
- so->so_head = NULL;
+ so->so_state &= ~SS_NOFDREF;
socket_unlock(so, 1);
soclose(so);
/* Drop reference on listening socket */
* Pass the pre-accepted socket to any interested socket filter(s).
* Upon failure, the socket would have been closed by the callee.
*/
- if (so->so_filt != NULL && (error = soacceptfilter(so)) != 0) {
+ if (so->so_filt != NULL && (error = soacceptfilter(so, head)) != 0) {
/* Drop reference on listening socket */
sodereference(head);
/* Propagate socket filter's error code to the caller */
* just causes the client to spin. Drop the socket.
*/
socket_lock(so, 1);
- so->so_state &= ~(SS_NOFDREF | SS_COMP);
- so->so_head = NULL;
+ so->so_state &= ~SS_NOFDREF;
socket_unlock(so, 1);
soclose(so);
sodereference(head);
if (dosocklock)
socket_lock(so, 1);
- so->so_state &= ~SS_COMP;
- so->so_head = NULL;
-
/* Sync socket non-blocking/async state with file flags */
if (fp->f_flag & FNONBLOCK) {
so->so_state |= SS_NBIO;
*slp = NULL;
- if (uaddr == USER_ADDR_NULL || uaddrlen == 0)
+ if (uaddr == USER_ADDR_NULL || uaddrlen == 0 ||
+ uaddrlen > (sizeof(struct sockaddr_in6) * SOCKADDRLIST_MAX_ENTRIES))
return (EINVAL);
sl = sockaddrlist_alloc(M_WAITOK);
} else if (ss.ss_len > sizeof (ss)) {
/*
* sockaddr_storage size is less than SOCK_MAXADDRLEN,
- * so the check here is inclusive. We could user the
+ * so the check here is inclusive. We could use the
* latter instead, but seems like an overkill for now.
*/
error = ENAMETOOLONG;
}
se = sockaddrentry_alloc(M_WAITOK);
- if (se == NULL)
+ if (se == NULL) {
+ error = ENOBUFS;
break;
+ }
sockaddrlist_insert(sl, se);