SNMP OctetString/ObjectDescription conversion asserts byte instead of []byte, causing panic #692
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar#692
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from GitHub.
Original GitHub issue: #2154
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/issues/2154
Original created: 2025-12-16T05:19:17Z
Summary
pkg/checker/snmp/client.goconverts SNMP PDU variables returned from the gosnmp library into Go types for use in the monitoring system.convertOctetStringandconvertObjectDescriptionfunctions incorrectly attempt to type-assertvariable.Valueas a singlebyteinstead of a byte slice[]byte.[]bytefor OctetString and ObjectDescription types, but the code tries to convert to a singlebyte, causing a panic.sysDescrused for device identification) will crash the application with a panic.Code with bug
Evidence
Example
The SNMP OID
1.3.6.1.2.1.1.1.0(sysDescr - system description) is one of the most fundamental SNMP OIDs used to identify network devices. This OID returns a DisplayString type, which is encoded as an OctetString in SNMP.When the gosnmp library queries this OID, it returns:
The code attempts:
This type assertion fails because:
[]byte(also known as[]uint8)byte(also known asuint8)The result is a panic:
interface conversion: interface {} is []uint8, not uint8Inconsistency with API documentation
Reference API documentation
From the gosnmp documentation at https://pkg.go.dev/github.com/gosnmp/gosnmp:
Example from the documentation:
The documentation clearly shows that OctetString values should be type-asserted to
[]byte, notbyte.Current API usage
pkg/checker/snmp/client.golines 268 and 296:Contradiction
The code attempts to convert
variable.Valueto a singlebyte, but the gosnmp library's API documentation and implementation clearly shows that OctetString and ObjectDescription values are returned as[]byte(byte slices), not single bytes.Inconsistency within the codebase
Reference code
pkg/checker/snmp/collector.golines 376-386:Current code
pkg/checker/snmp/client.golines 295-297:Comparison
The collector correctly handles string conversion by accepting
[]byteand converting it tostring. TheconvertStringfunction in the collector demonstrates the correct understanding that SNMP string values come as byte slices. However, theconvertOctetStringfunction in the client contradicts this by attempting to convert a singlebyte, which is inconsistent with both the gosnmp API and the codebase's own handling of similar data types.Failing test
Test script
Test output
The panic message confirms:
interface conversion: interface {} is []uint8, not uint8Full context
The SNMP client is part of ServiceRadar's monitoring system. The call chain is:
pkg/checker/snmp/service.go) - The main service that manages SNMP monitoring targetspkg/checker/snmp/collector.go) - Periodically polls SNMP devices by callingclient.Get(oids)pkg/checker/snmp/client.goline 107) - Executes SNMP queries using the gosnmp librarypkg/checker/snmp/client.goline 206) - Converts raw gosnmp responses to Go typespkg/checker/snmp/client.golines 267, 295) - Where the bug occursWhen monitoring any SNMP device, the collector will typically query basic system information including:
sysDescr(1.3.6.1.2.1.1.1.0) - System description (OctetString)sysContact(1.3.6.1.2.1.1.4.0) - System contact (OctetString)sysName(1.3.6.1.2.1.1.5.0) - System name (OctetString)sysLocation(1.3.6.1.2.1.1.6.0) - System location (OctetString)All of these fundamental OIDs return OctetString types, so any monitoring configuration that includes these OIDs will trigger the panic. The panic crashes the collector goroutine, preventing further data collection from the affected target. If error handling doesn't properly recover from the panic, it could crash the entire monitoring service.
External documentation
Why has this bug gone undetected?
This bug has gone undetected for several reasons:
Limited test coverage: The existing tests in the SNMP package use mocks extensively. The
collector_test.gofile only tests the collector with mock SNMP clients, never exercising the actual type conversion code paths with real gosnmp PDU structures.No integration tests with real SNMP data: While there is a file named
snmp_integration_test.go, it likely doesn't test against live SNMP devices or use real OctetString values from the gosnmp library. The type conversion functions have never been tested with actual gosnmp.SnmpPDU values that contain OctetString types.Uncommon data type in testing: String-type OIDs (OctetString, ObjectDescription) may not have been included in the test scenarios. Developers might have focused testing on numeric metrics (Counter32, Gauge32, Integer) which are more commonly used for monitoring metrics like CPU, memory, and bandwidth.
Recent code addition: The git history shows this code went through multiple linter fixes (
more linter fixes,fixing linter issues in client.go, etc.). The conversion functions may have been added recently or refactored during linting cleanup, potentially introducing the bug without adequate testing of the changes.Development/staging environment limitations: The development or staging environment might not have actual SNMP devices configured, or the test configurations might not include the common system OIDs (sysDescr, sysName, etc.) that would trigger this bug.
Collector-level type handling: Looking at
collector.goline 377, the collector has its ownconvertStringfunction that correctly handles[]bytevalues. This suggests that in some code paths, the data might flow through alternative conversion logic that masks this bug, or the affected code paths simply haven't been exercised in production yet.Recommended fix
Change both functions to correctly handle byte slices:
Additionally, consider adding error handling for robustness:
Imported GitHub comment.
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/issues/2154#issuecomment-3662493126
Original created: 2025-12-16T21:39:42Z
closing as completed