Bluetooth: Refuse peer RFCOMM address reading when not connected
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 28 Jan 2014 23:16:50 +0000 (15:16 -0800)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 13 Feb 2014 07:51:39 +0000 (09:51 +0200)
When we're not connected the peer address information is undefined. This
patch fixes the remote address getting to return a proper error in case
the sate is anything else than BT_CONNECTED.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/rfcomm/sock.c

index fb8158af1f39c33556b68a88722dd10f6b8c0bd7..00573fb79030788c6f65e55996adc174e32e3689 100644 (file)
@@ -528,6 +528,9 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
 
        BT_DBG("sock %p, sk %p", sock, sk);
 
+       if (peer && sk->sk_state != BT_CONNECTED)
+               return -ENOTCONN;
+
        memset(sa, 0, sizeof(*sa));
        sa->rc_family  = AF_BLUETOOTH;
        sa->rc_channel = rfcomm_pi(sk)->channel;