git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Tilman Vogel" <tilman.vogel@web.de>,
	"Jan Krüger" <jk@jk.gs>
Subject: Re: [PATCH] push: do not turn --delete '' into a matching push
Date: Tue, 23 Feb 2021 23:58:09 -0500	[thread overview]
Message-ID: <YDXc4XFwaOj/r3YK@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqq4ki21ioz.fsf@gitster.g>

On Tue, Feb 23, 2021 at 03:13:32PM -0800, Junio C Hamano wrote:

> When we added a syntax sugar "git push remote --delete <ref>" to
> "git push" as a synonym to the canonical "git push remote :<ref>"
> syntax at f517f1f2 (builtin-push: add --delete as syntactic sugar
> for :foo, 2009-12-30), we weren't careful enough to make sure that
> <ref> is not empty.
> 
> Blindly rewriting "--delete <ref>" to ":<ref>" means that an empty
> string <ref> results in refspec ":", which is the syntax to ask for
> "matching" push that does not delete anything.
> 
> Worse yet, if there were matching refs that can be fast-forwarded,
> they would have been published prematurely, even if the user feels
> that they are not ready yet to be pushed out, which would be a real
> disaster.
> 
> Noticed-by: Tilman Vogel <tilman.vogel@web.de>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> 
>  * So this time with an obvious test.  It is somewhat surprising
>    that this has been left unnoticed for the past 10 years.

Thanks, this looks like the obviously correct fix. I'm not too surprised
that nobody noticed. You have to add quoting to get an empty-string
argument in shell, and the non-delete case does notice and complain.

I did wonder if this was related to recent refactoring around the
refspec code (like negative refspecs), but I think this function is
independent of that anyway. Thanks for tracking down the original
culprit.

> diff --git a/builtin/push.c b/builtin/push.c
> index 03adb58602..194967ed79 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -115,7 +115,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
>  			else
>  				refspec_appendf(&rs, "refs/tags/%s", ref);
>  		} else if (deleterefs) {
> -			if (strchr(ref, ':'))
> +			if (strchr(ref, ':') || !*ref)
>  				die(_("--delete only accepts plain target ref names"));
>  			refspec_appendf(&rs, ":%s", ref);
>  		} else if (!strchr(ref, ':')) {

Just wondering if there are other similar bugs lurking:

  - could we see other strings that aren't empty, but also aren't plain
    target ref names? E.g., other punctuation like a "^" negative
    refspec? I guess that would produce ":^", which the refspec code
    will catch.

  - likewise, do any of these other else clauses blindly pass around an
    empty string? Yes, the final one does, but we catch it later in the
    refspec code.

So I think it really is this "blindly prepend a colon" part that is the
real bug. Anything else would create a nonsense refspec that will be
caught by the refspec code.

-Peff

  reply	other threads:[~2021-02-24  5:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23 23:13 [PATCH] push: do not turn --delete '' into a matching push Junio C Hamano
2021-02-24  4:58 ` Jeff King [this message]
2021-02-24  7:07 ` Elijah Newren

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=YDXc4XFwaOj/r3YK@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jk@jk.gs \
    --cc=tilman.vogel@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).