rebase: verify commit parameter

If the user specifies a base commit to switch to, check if it actually references a commit right away to avoid getting confused later on when it turns out to be an invalid object. Reported-by: LeSeulArtichaut <leseulartichaut@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jan 1, 2021 at 00:55 UTC ca5120c339de883c3f22161316416c91655651ab
1 file changed +3 -1
builtin/rebase.c
+3 -1
@@ -1906,7 +1906,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1906 die_if_checked_out(buf.buf, 1);
1907 options.head_name = xstrdup(buf.buf);
1908 /* If not is it a valid ref (branch or commit)? */
1909 - } else if (!get_oid(branch_name, &options.orig_head))
1909 + } else if (!get_oid(branch_name, &options.orig_head) &&
1910 + lookup_commit_reference(the_repository,
1911 + &options.orig_head))
1912 options.head_name = NULL;
1913 else
1914 die(_("fatal: no such branch/commit '%s'"),