Skip to content

fix: avoid panics on typed nil request bodies#289

Open
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-nil-bytes-buffer-body
Open

fix: avoid panics on typed nil request bodies#289
happysnaker wants to merge 1 commit into
hashicorp:mainfrom
happysnaker:fix-nil-bytes-buffer-body

Conversation

@happysnaker

@happysnaker happysnaker commented Jun 30, 2026

Copy link
Copy Markdown

Summary

  • treat typed nil pointer bodies as no body instead of dereferencing them
  • fix the panic reported for *bytes.Buffer(nil)
  • add focused regression coverage for typed nil *bytes.Buffer and *bytes.Reader request bodies

Why

The current getBodyReaderAndContentLength type-switch handles concrete pointer body types like *bytes.Buffer and *bytes.Reader, but it assumes the pointer value is non-nil once the dynamic type matches. That means a typed nil body can panic during request construction instead of behaving like an absent body.

This patch treats typed nil pointer/function bodies the same way as a nil body and keeps the resulting request behavior aligned with the existing no-body path.

Closes #188.

@happysnaker happysnaker requested a review from a team as a code owner June 30, 2026 14:25
@hashicorp-cla-app

hashicorp-cla-app Bot commented Jun 30, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@happysnaker

Copy link
Copy Markdown
Author

This should be ready for review on my side.

I have already signed the HashiCorp CLA previously, but the license/cla check is still showing as pending right after PR creation, so I'm waiting for that status to refresh.

Change summary:

  • treat typed nil pointer bodies like *bytes.Buffer(nil) as no body instead of dereferencing them
  • keep request construction aligned with the existing nil-body path
  • add focused regression coverage for typed nil *bytes.Buffer and *bytes.Reader bodies

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

Successfully merging this pull request may close these issues.

panic on nil *bytes.Buffer as body

1 participant