Protect against key not found in genHeader map in msg.go

Added checks to ensure the key HeaderMessageID exists in the genHeader map before attempting to operate on it in msg.go. This will prevent possible null pointer exceptions when trying to assign the key a value or append it to the mids slice.
This commit is contained in:
Winni Neessen 2023-11-29 17:34:15 +01:00
parent da21550dc9
commit 5a4f814061
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -758,7 +758,9 @@ func TestMsg_SetMessageIDWithValue(t *testing.T) {
t.Errorf("SetMessageID() failed. Expected value, got: empty")
return
}
m.genHeader[HeaderMessageID] = nil
if _, ok := m.genHeader[HeaderMessageID]; ok {
m.genHeader[HeaderMessageID] = nil
}
v := "This.is.a.message.id"
vf := "<This.is.a.message.id>"
m.SetMessageIDWithValue(v)
@ -779,7 +781,9 @@ func TestMsg_SetMessageIDRandomness(t *testing.T) {
m := NewMsg()
m.SetMessageID()
mid := m.GetGenHeader(HeaderMessageID)
mids = append(mids, mid[0])
if len(mid) > 0 {
mids = append(mids, mid[0])
}
}
c := make(map[string]int)
for i := range mids {