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

git pull --set-upstream segfaults on branchless repo.

From
CFClemens Fruhwirth <clemens@endorphin.org>
Date
Jul 5, 2021, 15:46 UTC
Message-ID
<CAG6gW_uHhfNiHGQDgGmb1byMqBA7xa8kuH1mP-wAPEe5Tmi2Ew@mail.gmail.com>

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

Run "git pull origin nixos-unstable --rebase --set-upstream" on a repo that had no branch set, e.g. when running "git branch" gave "* (no branch)"

What did you expect to happen? (Expected behavior) Pull from upstream and set upstream.

What happened instead? (Actual behavior)
Segfault with the following trace:
(gdb) bt
#0  0x000000000044a8c9 in do_fetch (transport=0x2557920,
rs=rs@entry=0x7ffd42335c00) at builtin/fetch.c:1568
#1  0x000000000044ac61 in fetch_one (remote=<optimized out>,
argc=1110662144, argv=0x7ffd42335fc8,
    prune_tags_ok=<optimized out>, use_stdin_refspecs=0) at builtin/fetch.c:1892
#2  0x000000000044af15 in cmd_fetch (argc=0, argv=0x7ffd42335fc8,
prefix=0x0) at builtin/fetch.c:1992
#3  0x0000000000406354 in run_builtin (p=0x70d3e0 <commands+960>,
argc=argc@entry=5, argv=argv@entry=0x7ffd42335fc0)
    at git.c:453
#4  0x00000000004065c3 in handle_builtin (argc=5, argv=0x7ffd42335fc0)
at git.c:704
#5  0x0000000000407c4a in run_argv (argcp=argcp@entry=0x7ffd42335e8c,
argv=argv@entry=0x7ffd42335e80) at git.c:771
#6  0x00000000004080a4 in cmd_main (argc=<optimized out>,
argc@entry=6, argv=<optimized out>,
    argv@entry=0x7ffd42335fb8) at git.c:902
#7  0x00000000004c614c in main (argc=6, argv=0x7ffd42335fb8) at common-main.c:52
(gdb) p branch
$1 = (struct branch *) 0x0

What's different between what you expected and what actually happened? Not segfault

Anything else you want to add:

Dropping the "--set-upstream" makes the segfault go away. Looking at builtin/fetch.c around L1568 I see,

        if (set_upstream) {
                struct branch *branch = branch_get("HEAD");
                [..]
                if (source_ref) {
                        if (!strcmp(source_ref->name, "HEAD") ||
                            starts_with(source_ref->name, "refs/heads/"))
                                install_branch_config(0,
                                                      branch->name, //
<- SEGFAULT HERE
                                                      transport->remote->name,
                                                      source_ref->name);
                        [..]
              }
        }

It's rather clear that branch is just NULL from the gdb session above, and the branch->name dereference fails. It might be useful to catch branch == NULL.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.31.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /nix/store/kxj6cblcsd1qcbbxlmbswwrn89zcmgd6-bash-4.4-p23/bin/bash uname: Linux 5.12.12 #1-NixOS SMP Fri Jun 18 08:02:52 UTC 2021 x86_64 compiler info: gnuc: 10.3 libc info: glibc: 2.32 $SHELL (typically, interactive shell): /var/run/current-system/sw/bin/zsh

[Enabled Hooks]
(Please cc me on replies, not subscribe to the mailing list).
-- 
Fruhwirth Clemens http://clemens.endorphin.org
Next: Jan Pokorný
Message 1 of 13 in “git pull --set-upstream segfaults on branchless repo.”
  1. Clemens FruhwirthJul 5, 2021
  2. Jan PokornýJul 19, 2021
  3. pull, fetch: fix segfault in --set-upstream optionÆvar Arnfjörð Bjarmason, Jul 19, 2021
  4. Junio C HamanoJul 19, 2021
  5. pull, fetch: fix segfault in --set-upstream optionÆvar Arnfjörð Bjarmason, Aug 23, 2021
  6. Clemens FruhwirthAug 24, 2021
  7. Ævar Arnfjörð BjarmasonAug 24, 2021
  8. pull, fetch: fix segfault in --set-upstream optionÆvar Arnfjörð Bjarmason, Aug 30, 2021
  9. Junio C HamanoAug 30, 2021
  10. pull, fetch: fix segfault in --set-upstream optionÆvar Arnfjörð Bjarmason, Aug 31, 2021
  11. Junio C HamanoAug 31, 2021
  12. Ævar Arnfjörð BjarmasonAug 31, 2021
  13. Junio C HamanoSep 1, 2021

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.