From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Per Cederqvist <cederp@opera.com>
Subject: Re: [PATCH] branch: segfault fixes and validation
Date: Thu, 21 Feb 2013 09:47:50 -0800 [thread overview]
Message-ID: <7vvc9lv9rt.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1361456285-29611-1-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Thu, 21 Feb 2013 21:18:05 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> branch_get() can return NULL (so far on detached HEAD only)...
Do you anticipate any other cases where the API call should validly
return NULL? I offhand do not, ...
> but some
> code paths in builtin/branch.c cannot deal with that and cause
> segfaults. Fix it.
>
> While at there, make sure to bail out when the user gives 2 or more
> arguments, but only the first one is processed.
>
> Reported-by: Per Cederqvist <cederp@opera.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> builtin/branch.c | 20 ++++++++++++++++++++
> t/t3200-branch.sh | 21 +++++++++++++++++++++
> 2 files changed, 41 insertions(+)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index 6371bf9..c1d688e 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -889,6 +889,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
> } else if (new_upstream) {
> struct branch *branch = branch_get(argv[0]);
>
> + if (argc > 1)
> + die(_("too many branches to set new upstream"));
> +
> + if (!branch)
> + die(_("could not figure out the branch name from '%s'"),
> + argc == 1 ? argv[0] : "HEAD");
... and find this "could not figure out" very unfriendly to the
user. Is it a bug in the implementation, silly Git failing to find
what branch the user meant? What recourse does the user have at
this point?
Or is it a user error to ask Git to operate on the branch pointed at
by HEAD, when HEAD does not refer to any branch? If that is the
case, then the message should say that there is no current branch to
operate on because the user is on a detached HEAD. That would point
the user in the right direction to correct the user error, no?
Of course, argv[0] may not be HEAD and in that case you may have to
say "no such branch %s" % argv[0] or something. The point is that
"could not figure out" feels a bit too lazy.
> @@ -901,6 +908,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
> struct branch *branch = branch_get(argv[0]);
> struct strbuf buf = STRBUF_INIT;
>
> + if (argc > 1)
> + die(_("too many branches to unset upstream"));
> +
> + if (!branch)
> + die(_("could not figure out the branch name from '%s'"),
> + argc == 1 ? argv[0] : "HEAD");
Likewise.
> @@ -916,6 +930,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
> int branch_existed = 0, remote_tracking = 0;
> struct strbuf buf = STRBUF_INIT;
>
> + if (!strcmp(argv[0], "HEAD"))
> + die(_("it does not make sense to create 'HEAD' manually"));
> +
> + if (!branch)
> + die(_("could not figure out the branch name from '%s'"), argv[0]);
Likewise.
Thanks.
next prev parent reply other threads:[~2013-02-21 17:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-21 12:27 "git branch HEAD" dumps core when on detached head (NULL pointer dereference) Per Cederqvist
2013-02-21 12:50 ` Duy Nguyen
2013-02-21 13:24 ` Per Cederqvist
2013-02-21 13:32 ` Duy Nguyen
2013-02-21 14:18 ` [PATCH] branch: segfault fixes and validation Nguyễn Thái Ngọc Duy
2013-02-21 17:47 ` Junio C Hamano [this message]
2013-02-22 11:47 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
2013-02-22 20:27 ` Junio C Hamano
2013-02-23 12:22 ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2013-02-23 20:01 ` Junio C Hamano
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=7vvc9lv9rt.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=cederp@opera.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
/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).