af_unix: fix shutdown parameter checking
authorXi Wang <xi.wang@gmail.com>
Sun, 26 Aug 2012 16:47:13 +0000 (16:47 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 31 Aug 2012 19:55:37 +0000 (15:55 -0400)
Return -EINVAL rather than 0 given an invalid "mode" parameter.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/unix/af_unix.c

index c5ee4ff613641b3f8439f1c9cb6b22d55a1ff7f2..8a84ab64cafd8db2a70b58550423fb1c1d6c58f1 100644 (file)
@@ -2060,10 +2060,14 @@ static int unix_shutdown(struct socket *sock, int mode)
        struct sock *sk = sock->sk;
        struct sock *other;
 
-       mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN);
-
-       if (!mode)
-               return 0;
+       if (mode < SHUT_RD || mode > SHUT_RDWR)
+               return -EINVAL;
+       /* This maps:
+        * SHUT_RD   (0) -> RCV_SHUTDOWN  (1)
+        * SHUT_WR   (1) -> SEND_SHUTDOWN (2)
+        * SHUT_RDWR (2) -> SHUTDOWN_MASK (3)
+        */
+       ++mode;
 
        unix_state_lock(sk);
        sk->sk_shutdown |= mode;