From da21550dc9295ed82ea0f487f63be1acb7fa300d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 29 Nov 2023 17:26:58 +0100 Subject: [PATCH] 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. --- msg.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/msg.go b/msg.go index 75d837d..dbce277 100644 --- a/msg.go +++ b/msg.go @@ -520,7 +520,9 @@ func (m *Msg) RequestMDNTo(t ...string) error { } tl = append(tl, a.String()) } - m.genHeader[HeaderDispositionNotificationTo] = tl + if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok { + m.genHeader[HeaderDispositionNotificationTo] = tl + } return nil } @@ -541,7 +543,9 @@ func (m *Msg) RequestMDNAddTo(t string) error { var tl []string tl = append(tl, m.genHeader[HeaderDispositionNotificationTo]...) tl = append(tl, a.String()) - m.genHeader[HeaderDispositionNotificationTo] = tl + if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok { + m.genHeader[HeaderDispositionNotificationTo] = tl + } return nil }