git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Avoid segfault when passed malformed refspec

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 2, 2008, 01:03 UTC
Message-ID
<7vzluk6ugn.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<BAYC1-PASMTP124F1019C2D2CD7AA81CF5AE310@CEZ.ICE>
Sean <seanlkml@sympatico.ca> writes:
Show 28 quoted lines
> 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?

Previous: SeanNext: Sean
Message 2 of 3 in “Avoid segfault when passed malformed refspec”
  1. Avoid segfault when passed malformed refspecSean, Feb 2, 2008
  2. Junio C HamanoFeb 2, 2008
  3. SeanFeb 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.