Skip to content

known_hosts fails to load on Android #6550

Description

@martinellison

Reproduction steps

Try to clone a repository in a program on Android.

Expected behavior

Repository cloned

Actual behavior

error loading known_hosts error

Version of libgit2 (release number or SHA1)

The rust crate is libgit2-sys version 0.15.0+1.6.3, if that is any help. And the git2 crate is version .17.0.

Operating system(s) tested

Android

Notes

  • this does not seem to to be the similar error as found on Windows.
  • I got my error via the rust front end, but I do not think it is a rust issue, so I am raising it here.

Analysis

I am now doing env::set_var("HOME", "/data"); before I call libgit2, and now I am getting a different error message now: invalid or unknown remote ssh hostkey. (This comment is about the issue in the Android context).

When I do a rust env::var("HOME") , I get an error environment variable not found . But the libgit2 C code is using the environment variable to find the home directory (and from that the known hosts file).

The loading known hosts error is generated at libgit2/transports/ssh.c:545. It runs load_known_hostsand if the result is negative, it generates the error. load_known_hosts (435) does git_sysdir_expand_homedir_file, git_str_joinpath, libssh2_knownhost_init, andlibssh2_knownhost_readfile. It seems to be looking for $HOME/.ssh/known_hosts and then slurping this file in.

git_sysdir_expand_homedir_file (in sysdir.c:640) calls git_sysdir_find_homedir and git_str_joinpath; git_sysdir_find_homedir (622) calls git_sysdir_find_in_dirlist;, which (548) calls git_sysdir_get and then runs the result and sets the path (maybe it is making the path absolute). git_sysdir_get (490) does git_sysdir_check_selector (just an error check) and reads the git_sysdir__dirs (436) array for git_sysdir_guess_home_dirs.

git_sysdir_guess_home_dirs (324) is #ifdefed on GIT_WIN32. if not we call git__getenv or get_passwd_home. If we are not 'sandboxed' it calls git__getenv with "HOME"". Outside Windows, git__getenv (util.c:768) calls getenv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions