Fix potential null pointer exceptions in msg.go

This commit adds conditions in msg.go file to check if the header 'HeaderDispositionNotificationTo' key exists in the map 'm.genHeader' before trying to associate it with a value. This prevents potential null pointer exceptions.
This commit is contained in:
Winni Neessen 2023-11-29 17:26:58 +01:00
parent fd313e23b6
commit da21550dc9
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

4
msg.go
View file

@ -520,7 +520,9 @@ func (m *Msg) RequestMDNTo(t ...string) error {
} }
tl = append(tl, a.String()) tl = append(tl, a.String())
} }
if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
m.genHeader[HeaderDispositionNotificationTo] = tl m.genHeader[HeaderDispositionNotificationTo] = tl
}
return nil return nil
} }
@ -541,7 +543,9 @@ func (m *Msg) RequestMDNAddTo(t string) error {
var tl []string var tl []string
tl = append(tl, m.genHeader[HeaderDispositionNotificationTo]...) tl = append(tl, m.genHeader[HeaderDispositionNotificationTo]...)
tl = append(tl, a.String()) tl = append(tl, a.String())
if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
m.genHeader[HeaderDispositionNotificationTo] = tl m.genHeader[HeaderDispositionNotificationTo] = tl
}
return nil return nil
} }