From f4a51a4c33adc527ffc90bd6f9015e4a0f87ad70 Mon Sep 17 00:00:00 2001 From: Helen Weller <38860767+helenosheaa@users.noreply.github.com> Date: Tue, 23 Mar 2021 10:09:51 -0400 Subject: [PATCH] Fix ipmi panic (#9035) --- plugins/inputs/ipmi_sensor/connection.go | 6 ++++-- plugins/inputs/ipmi_sensor/connection_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/ipmi_sensor/connection.go b/plugins/inputs/ipmi_sensor/connection.go index 7a1fb71df359a..b67ba06b9a619 100644 --- a/plugins/inputs/ipmi_sensor/connection.go +++ b/plugins/inputs/ipmi_sensor/connection.go @@ -32,8 +32,10 @@ func NewConnection(server, privilege, hexKey string) *Connection { security := server[0:inx1] connstr = server[inx1+1:] up := strings.SplitN(security, ":", 2) - conn.Username = up[0] - conn.Password = up[1] + if len(up) == 2 { + conn.Username = up[0] + conn.Password = up[1] + } } if inx2 > 0 { diff --git a/plugins/inputs/ipmi_sensor/connection_test.go b/plugins/inputs/ipmi_sensor/connection_test.go index 0f40464fbd83a..3be902e3264bc 100644 --- a/plugins/inputs/ipmi_sensor/connection_test.go +++ b/plugins/inputs/ipmi_sensor/connection_test.go @@ -33,6 +33,18 @@ func TestNewConnection(t *testing.T) { HexKey: "0001", }, }, + // test connection doesn't panic if incorrect symbol used + { + "USERID@PASSW0RD@lan(192.168.1.1)", + &Connection{ + Hostname: "192.168.1.1", + Username: "", + Password: "", + Interface: "lan", + Privilege: "USER", + HexKey: "0001", + }, + }, } for _, v := range testData {