ccfos / ccfos/huatuo

[Bug] dcbCollector.Update panics with "slice bounds out of range" when netlink returns short DCB message

Open Beginner friendly
#596 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.1k
Forks
137
Avg merge
3d 16h
Merged PRs (30d)
18

Description

## Problem

In `core/metrics/netdev_dcb.go`, the `dcbCollector.Update()` method iterates over netlink messages returned by `doDcbRequest()` and slices each message with `m[sizeofDcbmsg:]` without first checking the message length:

```go
for _, m := range msgs {
attrs, err := nl.ParseRouteAttr(m[sizeofDcbmsg:]) // line 153
...
}
```

`sizeofDcbmsg` is 4. If the kernel returns a netlink message shorter than 4 bytes (due to a malformed/truncated DCB response, driver bug, or kernel version incompatibility), `m[4:]` triggers a **`runtime error: slice bounds out of range`** panic, crashing the entire huatuo-bamai process.

## Reproduction

1. Run huatuo-bamai on a system with a DCB-capable NIC whose driver returns a truncated netlink DCB response
2. The `netdev_dcb` collector calls `doDcbRequest()` → `nl.ParseRouteAttr(m[sizeofDcbmsg:])`
3. If `len(m) < 4`, the process panics

## Expected Behavior

The collector should return an error instead of panicking.

## Fix

Add a length check before slicing:

```go
if len(m) < sizeofDcbmsg {
return nil, fmt.Errorf("dcb netlink message too short: got %d, want at least %d", len(m), sizeofDcbmsg)
}
```

Contributor guide

Open the contributing guide

Research direction

Read core/metrics/netdev_dcb.go, starting with dcbCollector.Update() and its doDcbRequest() results. Exercise the short-message path, or inspect existing collector tests if available, and verify that a message shorter than sizeofDcbmsg returns an error without panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux
Domain
networking, observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.