patch-2.1.27 linux/net/ipv4/tcp.c

Next file: linux/net/ipv6/addrconf.c
Previous file: linux/net/ipv4/ipmr.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.26/linux/net/ipv4/tcp.c linux/net/ipv4/tcp.c
@@ -1777,13 +1777,11 @@
 	int val;
 
 	if (level != SOL_TCP)
-	{
 		return tp->af_specific->setsockopt(sk, level, optname, 
 						   optval, optlen);
-	}
-
-  	if (optval == NULL)
-  		return(-EINVAL);
+	
+	if(optlen<sizeof(int))
+		return -EINVAL;
 
   	if (get_user(val, (int *)optval))
 		return -EFAULT;
@@ -1812,13 +1810,19 @@
 		   int *optlen)
 {
 	struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
-	int val,err;
+	int val;
+	int len;
 
 	if(level != SOL_TCP)
 	{
 		return tp->af_specific->getsockopt(sk, level, optname,
 						   optval, optlen);
 	}
+	
+	if(get_user(len,optlen))
+		return -EFAULT;
+		
+	len=min(len,sizeof(int));
 
 	switch(optname)
 	{
@@ -1832,11 +1836,11 @@
 			return(-ENOPROTOOPT);
 	}
 
-  	err = put_user(sizeof(int),(int *) optlen);
-	if (!err)
-		err = put_user(val,(int *)optval);
-
-  	return err;
+  	if(put_user(len, optlen))
+  		return -EFAULT;
+	if(copy_to_user(optval, &val,len))
+		return -EFAULT;
+  	return 0;
 }
 
 void tcp_set_keepalive(struct sock *sk, int val)

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