]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
Bluetooth: Fix dereference after NULL check
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Fri, 5 Oct 2012 13:56:54 +0000 (16:56 +0300)
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>
Sun, 7 Oct 2012 22:15:11 +0000 (06:15 +0800)
Move code dereferencing possible NULL pointer to the check branch.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
net/bluetooth/l2cap_sock.c

index 2542abd3336f16d6f9fe65f75ea309f7886a29b3..a71c4089d17502c02f28e31f4707c1a25271fcb5 100644 (file)
@@ -382,13 +382,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
                }
 
                memset(&sec, 0, sizeof(sec));
-               if (chan->conn)
+               if (chan->conn) {
                        sec.level = chan->conn->hcon->sec_level;
-               else
-                       sec.level = chan->sec_level;
 
-               if (sk->sk_state == BT_CONNECTED)
-                       sec.key_size = chan->conn->hcon->enc_key_size;
+                       if (sk->sk_state == BT_CONNECTED)
+                               sec.key_size = chan->conn->hcon->enc_key_size;
+               } else {
+                       sec.level = chan->sec_level;
+               }
 
                len = min_t(unsigned int, len, sizeof(sec));
                if (copy_to_user(optval, (char *) &sec, len))