Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic on nil *bytes.Buffer as body #188

Open
alexdulin opened this issue Apr 11, 2023 · 0 comments
Open

panic on nil *bytes.Buffer as body #188

alexdulin opened this issue Apr 11, 2023 · 0 comments

Comments

@alexdulin
Copy link

When NewRequestWithContext is given a nil *bytes.Buffer as the body, it panics. Best guess is that it is because the type of the body is being checked, but not that it is non-nil.

Reproduction code (example here):

package main

import (
	"bytes"
	"context"
	"net/http"

	"github.com/hashicorp/go-retryablehttp"
)

type config struct {
	Method string
	URL    string
	Body   *bytes.Buffer
}

func main() {
	cfg := config{
		Method: http.MethodGet,
		URL:    "https://example.com",
	}
	_, _ = retryablehttp.NewRequestWithContext(
		context.Background(),
		cfg.Method,
		cfg.URL,
		cfg.Body,
	)
}

Panic output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x5edb1c]

goroutine 1 [running]:
bytes.(*Buffer).Len(...)
	/usr/local/go-faketime/src/bytes/buffer.go:73
github.com/hashicorp/go-retryablehttp.getBodyReaderAndContentLength({0x63e680?, 0x0?})
	/tmp/gopath1053138375/pkg/mod/github.com/hashicorp/go-retryablehttp@v0.7.2/client.go:228 +0x35c
github.com/hashicorp/go-retryablehttp.NewRequestWithContext({0x6afd98, 0xc0000ac000}, {0x648621, 0x3}, {0x64c514, 0x13}, {0x63e680?, 0x0?})
	/tmp/gopath1053138375/pkg/mod/github.com/hashicorp/go-retryablehttp@v0.7.2/client.go:295 +0x5a
main.main()
	/tmp/sandbox1468963018/prog.go:22 +0x7b
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

No branches or pull requests

1 participant