Skip to contentSkip to conversation

af_unix: fix shutdown parameter checking

PATCH Applied Xi Wang 2 participants 2 messages Aug 27, 2012 – Aug 31, 2012

Subsystems (3)
lore
Share & tools
lore

Xi Wang

author
#0 lore raw

PATCH 1/1 af_unix: fix shutdown parameter checking

Return -EINVAL rather than 0 given an invalid "mode" parameter.

---
Another way to check "mode" is as in inet_shutdown():

	mode++;
	if ((mode & ~SHUTDOWN_MASK) || !mode)
		return -EINVAL;

This patch uses a simpler form, to check if "mode" is in the range SHUT_RD ... SHUT_RDWR.

---
 net/unix/af_unix.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/unix/af_unix.c +8 -4
index c5ee4ff..8a84ab6 100644
@@ -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;
Signature · 1 line
1.7.9.5