ClusterLabs / ClusterLabs/hawk-apiserver

Missing `return` Statements on JSON Decoding Errors

Open Beginner friendly
#68 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
12
Forks
12
Avg merge
33m
Merged PRs (30d)
2

Description

In `api/data_interface.go`, multiple HTTP handlers fail to terminate execution after encountering JSON decoding errors. They call `http.Error()` but do not include a `return` statement. This allows execution to proceed with uninitialized or partially decoded structures, leading to unexpected behavior, superfluous header warnings, and execution of commands with empty fields.

**Affected Handlers:**
- `FetchResourceUtilizations`
- `SubmitResourceUtilizations`
- `FetchNodeAttributes`
- `SubmitNodeAttributes`
- `FetchNodeUtilizations`
- `SubmitNodeUtilizations`
- `FetchResourceOperationAttributes`

**Example:**
```go
func SubmitNodeAttributes(w http.ResponseWriter, r *http.Request) {
var frontendNode struct {
NodeName string `json:"CibObject"`
Nvpairs []Nvpair `json:"nvpair"`
}

if err := json.NewDecoder(r.Body).Decode(&frontendNode); err != nil {
http.Error(w, "Invalid request", http.StatusBadRequest)
log.Printf("[SubmitNodeAttibutes] JSON decode error: %v", err)
// Missing return statement here
}
...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in api/data_interface.go and inspect the JSON decoding error paths in the seven affected handlers. Confirm that each http.Error call is followed by termination before any partially decoded data is used; done means invalid JSON produces the bad-request response without continuing handler execution or emitting superfluous headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.