git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sean <seanlkml@sympatico.ca>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Avoid segfault when passed malformed refspec
Date: Fri, 01 Feb 2008 17:03:04 -0800	[thread overview]
Message-ID: <7vzluk6ugn.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <BAYC1-PASMTP124F1019C2D2CD7AA81CF5AE310@CEZ.ICE> (seanlkml@sympatico.ca's message of "Fri, 1 Feb 2008 19:00:13 -0500")

Sean <seanlkml@sympatico.ca> writes:

> A refspec typo can cause a Null-pointer dereference and segmentation
> fault.  For instance, the space before the colon in the following
> example results in a segfault:
>
>    $ git fetch ../repo  refs/heads/* :refs/heads/*
>    Segmentation fault (core dumped)
>
> To avoid the segfault, set an empty refspec destination string
> if one isn't found by parsing.
>
> Signed-off-by: Sean Estabrooks <seanlkml@sympatico.ca>
> ---
>  remote.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/remote.c b/remote.c
> index 0e00680..414c73a 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -336,6 +336,8 @@ struct refspec *parse_ref_spec(int nr_refspec, const char **refspec)
>  			ep = gp;
>  		}
>  		rs[i].src = xstrndup(sp, ep - sp);
> +		if (!rs[i].dst)
> +			rs[i].dst = xstrdup("");
>  	}
>  	return rs;
>  }

I haven't followed the codepath carefully before responding, it
feels like sweeping the breakage under the carpet, without
fixing the real issue.

If the problem is a badly formatted input, shouldn't the code
die loudly with diagnostic message, instead of pretending as if
the user said something different (and sensible), especially
without telling the user that that is what the code is doing?

  reply	other threads:[~2008-02-02  1:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-02  0:00 [PATCH] Avoid segfault when passed malformed refspec Sean
2008-02-02  1:03 ` Junio C Hamano [this message]
2008-02-02  1:26   ` Sean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vzluk6ugn.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=seanlkml@sympatico.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).