diff --git a/net/local/local_recvmsg.c b/net/local/local_recvmsg.c index a49c7a03621..7a1eaa2e714 100644 --- a/net/local/local_recvmsg.c +++ b/net/local/local_recvmsg.c @@ -123,7 +123,7 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf, static void local_recvctl(FAR struct local_conn_s *conn, FAR struct msghdr *msg) { - FAR struct local_conn_s *peer = conn->lc_peer; + FAR struct local_conn_s *peer; struct cmsghdr *cmsg; int count; int *fds; @@ -131,7 +131,16 @@ static void local_recvctl(FAR struct local_conn_s *conn, net_lock(); - if (peer == NULL) + cmsg = CMSG_FIRSTHDR(msg); + count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int); + cmsg->cmsg_len = 0; + + if (count == 0) + { + goto out; + } + + if (conn->lc_peer == NULL) { peer = local_peerconn(conn); if (peer == NULL) @@ -139,16 +148,12 @@ static void local_recvctl(FAR struct local_conn_s *conn, goto out; } } - - if (peer->lc_cfpcount == 0) + else { - goto out; + peer = conn; } - cmsg = CMSG_FIRSTHDR(msg); - - count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int); - if (count == 0) + if (peer->lc_cfpcount == 0) { goto out; } diff --git a/net/local/local_sendmsg.c b/net/local/local_sendmsg.c index 9765284fe52..31c211415c1 100644 --- a/net/local/local_sendmsg.c +++ b/net/local/local_sendmsg.c @@ -61,6 +61,7 @@ static int local_sendctl(FAR struct local_conn_s *conn, FAR struct msghdr *msg) { + FAR struct local_conn_s *peer; FAR struct file *filep2; FAR struct file *filep; struct cmsghdr *cmsg; @@ -71,6 +72,12 @@ static int local_sendctl(FAR struct local_conn_s *conn, net_lock(); + peer = conn->lc_peer; + if (peer == NULL) + { + peer = conn; + } + for_each_cmsghdr(cmsg, msg) { if (!CMSG_OK(msg, cmsg) || @@ -84,7 +91,7 @@ static int local_sendctl(FAR struct local_conn_s *conn, fds = (int *)CMSG_DATA(cmsg); count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int); - if (count + conn->lc_cfpcount > LOCAL_NCONTROLFDS) + if (count + peer->lc_cfpcount > LOCAL_NCONTROLFDS) { ret = -EMFILE; goto fail; @@ -112,7 +119,7 @@ static int local_sendctl(FAR struct local_conn_s *conn, goto fail; } - conn->lc_cfps[conn->lc_cfpcount++] = filep2; + peer->lc_cfps[peer->lc_cfpcount++] = filep2; } } @@ -123,9 +130,9 @@ static int local_sendctl(FAR struct local_conn_s *conn, fail: while (i-- > 0) { - file_close(conn->lc_cfps[--conn->lc_cfpcount]); - kmm_free(conn->lc_cfps[conn->lc_cfpcount]); - conn->lc_cfps[conn->lc_cfpcount] = NULL; + file_close(peer->lc_cfps[--peer->lc_cfpcount]); + kmm_free(peer->lc_cfps[peer->lc_cfpcount]); + peer->lc_cfps[peer->lc_cfpcount] = NULL; } net_unlock();