Skip to content

Commit

Permalink
fix: check index before assignment (influxdata#10299)
Browse files Browse the repository at this point in the history
  • Loading branch information
MyaLongmire authored Dec 20, 2021
1 parent c6faf3d commit 973ffba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/snmp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,14 @@ func SnmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin
if strings.ContainsAny(oid, "::") {
// split given oid
// for example RFC1213-MIB::sysUpTime.0
s := strings.Split(oid, "::")
s := strings.SplitN(oid, "::", 2)
// node becomes sysUpTime.0
if s[1] == "" {
return "", oid, oid, oid, fmt.Errorf("cannot parse %v\n", oid)
}
node := s[1]
if strings.ContainsAny(node, ".") {
s = strings.Split(node, ".")
s = strings.SplitN(node, ".", 2)
// node becomes sysUpTime
node = s[0]
end = "." + s[1]
Expand Down
11 changes: 11 additions & 0 deletions plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,14 @@ func BenchmarkMibLoading(b *testing.B) {
require.NoError(b, err)
}
}

func TestCanNotParse(t *testing.T) {
s := &Snmp{
Fields: []Field{
{Oid: "RFC1213-MIB::"},
},
}

err := s.Init()
require.Error(t, err)
}

0 comments on commit 973ffba

Please sign in to comment.