fix: check index before assignment (#10299)

This commit is contained in:
Mya 2021-12-20 10:52:47 -07:00 committed by GitHub
parent c6faf3d3b4
commit 973ffba9fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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]

View File

@ -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)
}