rust-lang / rust-lang/git2-rs

Panic when authenticating with ssh key

Open
#823 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

uname -a output:
Linux HAL-9K 5.16.14-1-MANJARO #1 SMP PREEMPT Fri Mar 11 14:12:18 UTC 2022 x86_64 GNU/Linux

I am trying to push to a repository with an existing private key, with no passphrase. However, when pushing I get a segmentation fault.

remote_callbacks.credentials(|_url, username_from_url, _allowed_types| {
                    git2::Cred::ssh_key(
                        username_from_url.unwrap(),
                        None,
                        std::path::Path::new(&format!("{}/.ssh/github", env::var("HOME").unwrap())),
                        None,
                    )
                });

The full source code can be found here (nevermind the hard-coded paths, the project is still a WIP)

Running valgrind on the target binary produces the following output:

==52788== Conditional jump or move depends on uninitialised value(s)
==52788==    at 0x4926FA0: ??? (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x492D0AC: git_remote_push (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x4BC9F4: git2::remote::Remote::push (remote.rs:329)
==52788==    by 0x4B8F00: <nabu::git::WatchedRepository as nabu::git::Repository>::push (git.rs:146)
==52788==    by 0x20ECC1: nabu::watch::Watch<R>::run (watch.rs:203)
==52788==    by 0x20C20B: nabu::watch::WatchArgs::run (watch.rs:87)
==52788==    by 0x207878: nabu::main (main.rs:52)
==52788==    by 0x216A3A: core::ops::function::FnOnce::call_once (function.rs:227)
==52788==    by 0x22141D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:123)
==52788==    by 0x21AA60: std::rt::lang_start::{{closure}} (rt.rs:145)
==52788==    by 0x809E8F: std::rt::lang_start_internal (function.rs:259)
==52788==    by 0x21AA2F: std::rt::lang_start (rt.rs:144)
==52788== 
==52788== Invalid read of size 8
==52788==    at 0x4926FC0: ??? (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x492D0AC: git_remote_push (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x4BC9F4: git2::remote::Remote::push (remote.rs:329)
==52788==    by 0x4B8F00: <nabu::git::WatchedRepository as nabu::git::Repository>::push (git.rs:146)
==52788==    by 0x20ECC1: nabu::watch::Watch<R>::run (watch.rs:203)
==52788==    by 0x20C20B: nabu::watch::WatchArgs::run (watch.rs:87)
==52788==    by 0x207878: nabu::main (main.rs:52)
==52788==    by 0x216A3A: core::ops::function::FnOnce::call_once (function.rs:227)
==52788==    by 0x22141D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:123)
==52788==    by 0x21AA60: std::rt::lang_start::{{closure}} (rt.rs:145)
==52788==    by 0x809E8F: std::rt::lang_start_internal (function.rs:259)
==52788==    by 0x21AA2F: std::rt::lang_start (rt.rs:144)
==52788==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==52788== 
==52788== 
==52788== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==52788==  Access not within mapped region at address 0x0
==52788==    at 0x4926FC0: ??? (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x492D0AC: git_remote_push (in /usr/lib/libgit2.so.1.4.0)
==52788==    by 0x4BC9F4: git2::remote::Remote::push (remote.rs:329)
==52788==    by 0x4B8F00: <nabu::git::WatchedRepository as nabu::git::Repository>::push (git.rs:146)
==52788==    by 0x20ECC1: nabu::watch::Watch<R>::run (watch.rs:203)
==52788==    by 0x20C20B: nabu::watch::WatchArgs::run (watch.rs:87)
==52788==    by 0x207878: nabu::main (main.rs:52)
==52788==    by 0x216A3A: core::ops::function::FnOnce::call_once (function.rs:227)
==52788==    by 0x22141D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:123)
==52788==    by 0x21AA60: std::rt::lang_start::{{closure}} (rt.rs:145)
==52788==    by 0x809E8F: std::rt::lang_start_internal (function.rs:259)
==52788==    by 0x21AA2F: std::rt::lang_start (rt.rs:144)
==52788==  If you believe this happened as a result of a stack
==52788==  overflow in your program's main thread (unlikely but
==52788==  possible), you can try to increase the size of the
==52788==  main thread stack using the --main-stacksize= flag.
==52788==  The main thread stack size used in this run was 8388608.
==52788== 
==52788== HEAP SUMMARY:
==52788==     in use at exit: 771,648 bytes in 14,221 blocks
==52788==   total heap usage: 32,828 allocs, 18,607 frees, 3,069,508 bytes allocated
==52788== 
==52788== LEAK SUMMARY:
==52788==    definitely lost: 0 bytes in 0 blocks
==52788==    indirectly lost: 0 bytes in 0 blocks
==52788==      possibly lost: 1,324 bytes in 7 blocks
==52788==    still reachable: 770,324 bytes in 14,214 blocks
==52788==         suppressed: 0 bytes in 0 blocks
==52788== Rerun with --leak-check=full to see details of leaked memory
==52788== 
==52788== Use --track-origins=yes to see where uninitialised values come from
==52788== For lists of detected and suppressed errors, rerun with: -s
==52788== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the callback in nabu's src/git.rs and the git2::remote::Remote::push call at remote.rs:329, then reproduce the SSH-key push under Valgrind. Trace the failure through the libgit2 boundary; done means the push no longer segfaults and the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.