[PATCH] Do not dereference a NULL pointer in tsocket
Jeremy Allison
jra at samba.org
Wed Jun 22 17:15:41 UTC 2016
On Wed, Jun 22, 2016 at 03:39:28PM +0200, Andreas Schneider wrote:
> Review and push appreciated!
Should this be:
if (lrbsda != NULL) {
instead of:
if (is_inet) {
As that's the actual pointer in being used here ?
Seems safer in case is_inet gets divorced from the
lrbsda pointer initialization...
>
> --
> Andreas Schneider GPG-ID: CC014E3D
> Samba Team asn at samba.org
> www.samba.org
> From 59e7caafe68128c17cab56ec57007b0eed80c416 Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Wed, 22 Jun 2016 15:36:59 +0200
> Subject: [PATCH] tsocket: Do not dereference a NULL pointer
>
> If 'is_inet' is not set the lrbsda pointer is not allocated and we will
> end up dereferencing a NULL pointer.
>
> Found by Coverity.
>
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
> lib/tsocket/tsocket_bsd.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
> index 9608dde..bc7ed9c 100644
> --- a/lib/tsocket/tsocket_bsd.c
> +++ b/lib/tsocket/tsocket_bsd.c
> @@ -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 (is_inet) {
> + ret = getsockname(state->fd,
> + &lrbsda->u.sa,
> + &lrbsda->sa_socklen);
> + if (ret == -1) {
> + tevent_req_error(req, errno);
> + goto post;
> + }
> }
>
> tevent_req_done(req);
> --
> 2.9.0
>
More information about the samba-technical
mailing list