patch-2.1.91 linux/net/socket.c

Next file: linux/net/sunrpc/auth_unix.c
Previous file: linux/net/packet/af_packet.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.90/linux/net/socket.c linux/net/socket.c
@@ -646,15 +646,17 @@
 		goto out;
 
 	retval = get_fd(sock->inode);
-	if (retval < 0) {
-		sock_release(sock);
-		goto out;
-	}
+	if (retval < 0)
+		goto out_release;
+	sock->file = fcheck(retval);
 
-	sock->file = current->files->fd[retval];
 out:
 	unlock_kernel();
 	return retval;
+
+out_release:
+	sock_release(sock);
+	goto out;
 }
 
 /*
@@ -787,9 +789,8 @@
 {
 	struct inode *inode;
 	struct socket *sock, *newsock;
-	int err;
+	int err, len;
 	char address[MAX_SOCK_ADDR];
-	int len;
 
 	lock_kernel();
 	sock = sockfd_lookup(fd, &err);
@@ -815,7 +816,7 @@
 
 	if ((err = get_fd(inode)) < 0) 
 		goto out_release;
-	newsock->file = current->files->fd[err];
+	newsock->file = fcheck(err);
 
 	if (upeer_sockaddr)
 	{
@@ -1141,19 +1142,21 @@
 	char address[MAX_SOCK_ADDR];
 	struct iovec iov[UIO_FASTIOV];
 	unsigned char ctl[sizeof(struct cmsghdr) + 20];	/* 20 is size of ipv6_pktinfo */
-	struct msghdr msg_sys;
-	int err= -EINVAL;
-	int total_len;
 	unsigned char *ctl_buf = ctl;
+	struct msghdr msg_sys;
+	int err, total_len;
 	
 	lock_kernel();
 
-	err=-EFAULT;
+	err = -EFAULT;
 	if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
 		goto out; 
+
 	/* do not move before msg_sys is valid */
-	if (msg_sys.msg_iovlen>UIO_MAXIOV)
+	err = -EINVAL;
+	if (msg_sys.msg_iovlen > UIO_MAXIOV)
 		goto out;
+
 	/* This will also move the address data into kernel space */
 	err = verify_iovec(&msg_sys, iov, address, VERIFY_READ);
 	if (err < 0) 
@@ -1163,7 +1166,7 @@
 
 	sock = sockfd_lookup(fd, &err);
 	if (!sock) 
-		goto out; 
+		goto out_freeiov;
 
 	if (msg_sys.msg_controllen) 
 	{
@@ -1197,9 +1200,10 @@
 	if (ctl_buf != ctl)    
 		sock_kfree_s(sock->sk, ctl_buf, msg_sys.msg_controllen);
 failed2:
+	sockfd_put(sock);
+out_freeiov:
 	if (msg_sys.msg_iov != iov)
 		kfree(msg_sys.msg_iov);
-	sockfd_put(sock);
 out:       
 	unlock_kernel();
 	return err;
@@ -1228,16 +1232,13 @@
 	int *uaddr_len;
 	
 	lock_kernel();
+	err=-EFAULT;
 	if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
-	{
-		err=-EFAULT;
 		goto out;
-	}
-	if (msg_sys.msg_iovlen>UIO_MAXIOV)
-	{
-		err=-EINVAL;
+
+	err=-EINVAL;
+	if (msg_sys.msg_iovlen > UIO_MAXIOV)
 		goto out;
-	}
 	
 	/*
 	 *	Save the user-mode address (verify_iovec will change the

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov