Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Panic (Nil Pointer Dereference) when calling methods on client after ovh.NewClient failure #89

@Powma

Description

@Powma

Hello,

When ovh.NewClient returns an error and this error is ignored by the caller, attempting to call any method on the resulting nil client leads to a panic due to a nil pointer dereference. This results in a segmentation fault (SIGSEGV) and application crash.

package main

import (
	"fmt"

	"github.com/ovh/go-ovh/ovh"
)

// PartialMe holds the first name of the currently logged-in user.
// Visit https://api.ovh.com/console/#/me#GET for the full definition
type PartialMe struct {
	Firstname string `json:"firstname"`
}

// Instantiate an OVH client and get the firstname of the currently logged-in user.
// Visit https://api.ovh.com/createToken/index.cgi?GET=/me to get your credentials.
func main() {
	var me PartialMe

	client, _ := ovh.NewClient(
		"ovh-eu",
		"xxxx",
		"xxxxx",
		"xxxxxx",
	)
	client.Get("/me", &me)
	fmt.Printf("Welcome %s!\n", me.Firstname)
}
go run main.go                                                                                                
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x60 pc=0x100dd1d3c]

goroutine 1 [running]:
github.com/ovh/go-ovh/ovh.(*Client).NewRequest(0x0, {0x100e1414c, 0x3}, {0x100e14149?, 0x0?}, {0x0?, 0x0?}, 0x1)
        /Users/Matthias/go/pkg/mod/github.com/ovh/[email protected]/ovh/ovh.go:325 +0x8c
github.com/ovh/go-ovh/ovh.(*Client).CallAPIWithContext(0x0, {0x100f25d60, 0x101155dc0}, {0x100e1414c?, 0x100e1ecf1?}, {0x100e14149?, 0x100e1ed11?}, {0x0?, 0x0?}, {0x100ea8960, ...}, ...)
        /Users/Matthias/go/pkg/mod/github.com/ovh/[email protected]/ovh/ovh.go:446 +0x5c
github.com/ovh/go-ovh/ovh.(*Client).CallAPI(...)
        /Users/Matthias/go/pkg/mod/github.com/ovh/[email protected]/ovh/ovh.go:422
github.com/ovh/go-ovh/ovh.(*Client).Get(...)
        /Users/Matthias/go/pkg/mod/github.com/ovh/[email protected]/ovh/ovh.go:193
main.main()
        /Users/Matthias/Documents/OVH SMS/GO SMS OVH/main.go:26 +0xac
exit status 2

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