Smack: fix dereferenced before check
authorVasyl Gomonovych <gomonovych@gmail.com>
Thu, 21 Dec 2017 15:57:52 +0000 (16:57 +0100)
committerCasey Schaufler <casey@schaufler-ca.com>
Wed, 27 Dec 2017 22:43:19 +0000 (14:43 -0800)
This patch fixes the warning reported by smatch:
security/smack/smack_lsm.c:2872 smack_socket_connect() warn:
variable dereferenced before check 'sock->sk' (see line 2869)

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
security/smack/smack_lsm.c

index 14cc794..30f2c3d 100644 (file)
@@ -2866,12 +2866,16 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
 #endif
 #ifdef SMACK_IPV6_SECMARK_LABELING
        struct smack_known *rsp;
-       struct socket_smack *ssp = sock->sk->sk_security;
+       struct socket_smack *ssp;
 #endif
 
        if (sock->sk == NULL)
                return 0;
 
+#ifdef SMACK_IPV6_SECMARK_LABELING
+       ssp = sock->sk->sk_security;
+#endif
+
        switch (sock->sk->sk_family) {
        case PF_INET:
                if (addrlen < sizeof(struct sockaddr_in))