Skip to content

load_known_hosts: do not fail if homedir is invalid#7056

Closed
JonasVautherin wants to merge 1 commit into
libgit2:mainfrom
JonasVautherin:fix-android-known-hosts
Closed

load_known_hosts: do not fail if homedir is invalid#7056
JonasVautherin wants to merge 1 commit into
libgit2:mainfrom
JonasVautherin:fix-android-known-hosts

Conversation

@JonasVautherin

Copy link
Copy Markdown
Contributor

My suggested patch for #6550.

Without it, checking the known_hosts will always fail if the homedir is invalid, even if certificate_check is set. With this patch, it will ignore the known_hosts check and fallback to certificate_check (if set).

@JonasVautherin

Copy link
Copy Markdown
Contributor Author

@ethomson: I just wanted to mention that this change was discussed with you in #6550 😇. Also I have been using it since March (on Linux and Android) and haven't seen a problem.

@setoelkahfi

Copy link
Copy Markdown

@JonasVautherin Hey, I would like to test this patch. Do you use git2-rs?

@setoelkahfi

Copy link
Copy Markdown

I'm having this issue currently. Got it working by setting up HOME environment variable and the certificate check callback.

    env::set_var("HOME", "/data");
    // more codes
   let mut builder = RepoBuilder::new();
    builder.remote_create(|repo, _name, url| {
        // Name our remote deployment.
        repo.remote("smbcloud", url)
    });
    let mut callbacks = RemoteCallbacks::new();
    let mut fetch_options = FetchOptions::new();

    callbacks.credentials(|_, _, _| {
        let pub_key_path = app_data_dir.join(".ssh").join("id_ed25519.pub");
        let priv_key_path = app_data_dir.join(".ssh").join("id_ed25519");
        let credentials = Cred::ssh_key(
            "git",
            Some(pub_key_path.as_path()),
            priv_key_path.as_path(),
            None,
        )
        .expect("Could not create credentials object");
        Ok(credentials)
    });
    callbacks.certificate_check(|_a, _b| Ok(CertificateCheckStatus::CertificateOk));

@JonasVautherin

Copy link
Copy Markdown
Contributor Author

I'm using the C library. This patch works for me on my fork 👍.

@setoelkahfi

Copy link
Copy Markdown

I'm using the C library. This patch works for me on my fork 👍.

I see. I'll try to use your fork from my Rust project. If that's too complicated, I'm happy with my current workaround.

@JonasVautherin

JonasVautherin commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

@ethomson: Should I just close this?

@ethomson

ethomson commented May 6, 2026

Copy link
Copy Markdown
Member

Manually merged; thanks for the fix

@ethomson ethomson closed this May 6, 2026
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jul 19, 2026
v1.9.6

This release includes a few small but important bugfixes.

* load_known_hosts: do not fail if homedir is invalid
  by @JonasVautherin in libgit2/libgit2#7056
* Fix segfault on Android when no HOME set by @501st-alpha1 in
  libgit2/libgit2#7309
* cmake: bring back hidden visibility for the static build by
  @carlosmn in libgit2/libgit2#7288


v1.9.5

This is a security release with multiple changes.

* Fix for blame error handling on hunk creation failures

  `hunk_from_entry` can return `NULL` on error; handle that and
  return an error.

* Fix for potential PCRE memory access: 1-byte heap-buffer-overflow
  WRITE in bundled PCRE 8.45 reachable via revspec

  `git_revparse_single` accepts revspecs of the form `:/<pattern>`
  (the "grep by commit message" shorthand) and forwards `<pattern>`
  directly to libgit2's regex backend. When libgit2 is using its builtin
  regular expression engine, this causes a heap buffer overflow.

* Fix for CVE-2026-53586: give auth callback current host

  libgit2's builtin HTTP transport follows offsite redirects for the
  initial smart HTTP request by default. If the redirected server then
  returns 401 Unauthorized, libgit2 asks the application credential
  callback for credentials using the original remote URL, not the
  redirected URL. The returned credential is then attached to the next
  request to the redirected host as an Authorization header.

* Fix for CVE-2026-53587: libgit2 version 1.9.4 and below is vulnerable
  to a heap out-of-bounds read in `set_data` in
  `src/libgit2/transports/smart_pkt.c`.

  When given capabilities, we check for the object-format capability; we
  need to ensure that the current packet buffer is large enough before
  actually doing the check.

* Fix for CVE-2026-53585: Unbounded Memory Allocation via Delta
  Object Result-Size Header

  Potential denial of service because `git_delta_apply` reads the
  claimed result size (`res_sz`) from the delta object header — data
  entirely controlled by the sender — and immediately allocates a
  buffer of that size.

* Fix for CVE-2026-53584: submodule: check paths for escaping

  A crafted repository with a submodule whose path contains traversal
  components (e.g. "../") can cause the library to create directories
  outside the repository's working tree.

* Fix for CVE-2026-53583: inverted IP SubjectAltName comparison in
  OpenSSL backend.

  An inverted comparison in the OpenSSL TLS backend causes IP
  SubjectAltName (SAN) verification to accept certificates with
  mismatched IP addresses and reject certificates with correct IP
  addresses. This allows a network attacker with a valid CA-signed
  certificate containing any IP SAN to perform MITM attacks against
  libgit2 clients connecting to IP-literal HTTPS URLs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants