summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-10-02 14:40:23 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-10-02 14:40:23 +0000
commite00abcef163736430583ff4abd45f99ba5b50c8f (patch)
treedd575650abfdfbc75341e156afbd3598402f77c8 /sys/kern
parentdbee596f3d9528d981bbadc8302bc2b969966e39 (diff)
A closed, disconnected, or otherwise failed socket is still a socket
and should return stat information instead of EINVAL from deep in the guts of tcp_usrreq. While there, put some more information into struct stat, inspired by FreeBSD. EINVAL problem reported in PR 5943
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sys_socket.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 9ebffb76bc8..3665003969b 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_socket.c,v 1.12 2008/05/23 15:51:12 thib Exp $ */
+/* $OpenBSD: sys_socket.c,v 1.13 2008/10/02 14:40:22 deraadt Exp $ */
/* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */
/*
@@ -167,9 +167,17 @@ soo_stat(struct file *fp, struct stat *ub, struct proc *p)
bzero((caddr_t)ub, sizeof (*ub));
ub->st_mode = S_IFSOCK;
- return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
+ if ((so->so_state & SS_CANTRCVMORE) == 0 ||
+ so->so_rcv.sb_cc != 0)
+ ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
+ if ((so->so_state & SS_CANTSENDMORE) == 0)
+ ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+ ub->st_uid = so->so_euid;
+ ub->st_gid = so->so_egid;
+ (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
(struct mbuf *)ub, (struct mbuf *)0,
(struct mbuf *)0, p));
+ return (0);
}
/* ARGSUSED */