Skip to content

Bad interaction with empty http.proxy in .gitconfig and GIT_PROXY_AUTO #5220

@fredrikekre

Description

@fredrikekre

There is some bad interaction with empty http.proxy in .gitconfig and GIT_PROXY_AUTO. I noticed this when we upgraded to libgit2 0.28 for Julia (JuliaLang/julia#33111). For reasons I don't know I had an empty http.proxy in .gitconfig and libgit2 then fails to clone/fetch. I am guessing here, but maybe related to this changelog entry for 0.28.0:

HTTP proxy support is now builtin; libcurl is no longer used to support
proxies and is removed as a dependency.

Reproduction steps

.gitconfig:

$ cat .gitconfig
[http]
    proxy =

C-program:

#include <stdio.h>
#include <dlfcn.h>
#include "include/git2.h"

// Compile:
//     gcc -o bug bug.c -ldl
// Run:
//     ./bug ./libgit2.so
int main(int argc, char *argv[]){
    if (argc != 2) {
        fprintf(stderr, "Wrong number of arguments\n");
        return 1;
    }

    void *handle;
    int (*git_libgit2_init)(void);
    int (*git_clone)(git_repository **out, const char *url, const char *local_path, const git_clone_options *options);
    git_error* (*git_error_last)(void);

    // dlopen and initialize libgit2
    handle = dlopen(argv[1], RTLD_LAZY);
    git_libgit2_init = dlsym(handle, "git_libgit2_init");
    git_libgit2_init();

    // git clone arguments
    git_repository *repo = NULL;
    const char *url = "https://github.com/octocat/Spoon-Knife.git";
    const char *path = "/tmp/Spoon-Knife";
    git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
    clone_opts.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO; // <-- This is key

    // git clone
    git_clone = dlsym(handle, "git_clone");
    git_error_last = dlsym(handle, "git_error_last");
    int err = git_clone(&repo, url, path, &clone_opts);
    if (err != 0) {
        git_error* gerror = git_error_last();
        fprintf(stderr, "git clone failed. Message: %s, klass: %i, ret: %i\n", gerror->message, gerror->klass, err);
    }

    dlclose(handle);
    return err;
}
$ gcc -o bug bug.c -ldl

$ ./bug ./libgit2.so.0.28.3
git clone failed. Message: unrecognized URL prefix, klass: 12, ret: -1

$ ./bug ./libgit2.so.0.28.2
git clone failed. Message: unrecognized URL prefix, klass: 12, ret: -1

$ ./bug ./libgit2.so.0.28.1
git clone failed. Message: unrecognized URL prefix, klass: 12, ret: -1

$ ./bug ./libgit2.so.0.28.0
git clone failed. Message: unrecognized URL prefix, klass: 12, ret: -1

$ ./bug ./libgit2.so.0.27.9 # works

Expected behavior

Presumably the empty entry should be ignored. This is what seems to happen in libgit 0.27.9, and git does not complain either).

Actual behavior

See above.

Version of libgit2 (release number or SHA1)

Fails on 0.28.0, 0.28.1, 0.28.2, 0.28.3 and master (5fc27aa). Works on 0.27.9.

Operating system(s) tested

Linux x86_64 (Ubuntu)

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