Skip to content
Merged
24 changes: 17 additions & 7 deletions agent/kvs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,30 @@
}

// Check the content-length
if req.ContentLength > int64(s.agent.config.KVMaxValueSize) {
maxSize := int64(s.agent.config.KVMaxValueSize)

switch {
case req.ContentLength < 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case req.ContentLength < 0:
case !req.ContentLength || req.ContentLength <= 0:

return nil, HTTPError{
StatusCode: http.StatusBadRequest,
Reason: fmt.Sprintf("Request does not specify content-length .Expected content-length between 1 and %d .", maxSize),
}
case req.ContentLength > maxSize:
return nil, HTTPError{
StatusCode: http.StatusRequestEntityTooLarge,
Reason: fmt.Sprintf("Request body(%d bytes) too large, max size: %d bytes. See %s.",
req.ContentLength, s.agent.config.KVMaxValueSize, "https://developer.hashicorp.com/docs/agent/config/config-files#kv_max_value_size"),
req.ContentLength, maxSize, "https://developer.hashicorp.com/docs/agent/config/config-files#kv_max_value_size"),
}
}

// Copy the value
buf := bytes.NewBuffer(nil)
if _, err := io.Copy(buf, req.Body); err != nil {
return nil, err
default:
// Copy the value
buf := bytes.NewBuffer(nil)
if _, err := io.Copy(buf, req.Body); err != nil {
return nil, err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add jira tickets to oss repo prs.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for this.

applyReq.DirEnt.Value = buf.Bytes()

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / dev-build / build

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-enums

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-enums

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-enums

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-enums

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-enums

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint-32bit / lint

undefined: buf (typecheck)

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / integration-test-with-deployer

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: buf (typecheck)

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / build-amd64

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / build-386

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / dev-build / build

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / goldenfile-check

undefined: buf

Check failure on line 260 in agent/kvs_endpoint.go

View workflow job for this annotation

GitHub Actions / build-arm

undefined: buf

// Make the RPC
var out bool
Expand Down
Loading