Skip to content

nil pointer dereference when connecting to SSH based URLs with invalid proxy address #900

@anandf

Description

@anandf

When trying to list references from a remote git repository, through a socks5 proxy, there is a nil pointer dereference operation causing the code to panic. In the below code, I am setting proxy server url as socks5://127.0.0.1:1080. If the proxy server is running, then the code behaves correctly, but if the proxy server is not running, the code panics at this line of code session, err := gitClient.NewUploadPackSession(ep, auth)

Reproducer code:

package main

import (
	"fmt"

	"github.com/go-git/go-git/v5/plumbing/transport"
	"github.com/go-git/go-git/v5/plumbing/transport/client"
	"github.com/go-git/go-git/v5/plumbing/transport/ssh"
)

func main() {
	ep, err := transport.NewEndpoint("[email protected]:anandf/openshift-gitops-microshift.git")
	if err != nil {
		fmt.Println(err)
		return
	}
	ep.Proxy = transport.ProxyOptions{URL: "socks5://127.0.0.1:1080"}
	gitClient, err := client.NewClient(ep)
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
	auth, err := ssh.NewPublicKeysFromFile("git", "/home/anjoseph/.ssh/id_rsa", "")
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
	session, err := gitClient.NewUploadPackSession(ep, auth)
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
	ar, err := session.AdvertisedReferences()
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
	allRefs, err := ar.AllReferences()
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
	fmt.Println(allRefs)
	err = session.Close()
	if err != nil {
		fmt.Println("Error:" + err.Error())
		return
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions