tsocket: Do not dereference a NULL pointer
authorAndreas Schneider <asn@samba.org>
Wed, 22 Jun 2016 13:36:59 +0000 (15:36 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 30 Jun 2016 00:53:01 +0000 (02:53 +0200)
Make sure the lrbsda pointer is not allocated and we will
not end up dereferencing a NULL pointer. In practice this
can't happen, but this change links the pointer with the
code that uses it.

Found by Coverity.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Jun 30 02:53:02 CEST 2016 on sn-devel-144

lib/tsocket/tsocket_bsd.c

index 9608dded535f6ef99e400b26cd98c5a09f0d3f35..708d17edc321094b9423e082cca8a101078a2757 100644 (file)
@@ -2327,10 +2327,14 @@ static struct tevent_req *tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
                goto post;
        }
 
-       ret = getsockname(state->fd, &lrbsda->u.sa, &lrbsda->sa_socklen);
-       if (ret == -1) {
-               tevent_req_error(req, errno);
-               goto post;
+       if (lrbsda != NULL) {
+               ret = getsockname(state->fd,
+                                 &lrbsda->u.sa,
+                                 &lrbsda->sa_socklen);
+               if (ret == -1) {
+                       tevent_req_error(req, errno);
+                       goto post;
+               }
        }
 
        tevent_req_done(req);