Refactored null checks in msgwriter.go

Extended null check conditions in msgwriter.go to prevent potential nil pointer dereference. This change ensures robustness in error handling in scenarios where FROM header or envelope FROM is either not existent or nil.
This commit is contained in:
Winni Neessen 2023-11-29 16:56:32 +01:00
parent ca896bd641
commit b63d4803f1
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -67,13 +67,13 @@ func (mw *msgWriter) writeMsg(m *Msg) {
// Set the FROM header (or envelope FROM if FROM is empty) // Set the FROM header (or envelope FROM if FROM is empty)
hf := true hf := true
f, ok := m.addrHeader[HeaderFrom] f, ok := m.addrHeader[HeaderFrom]
if !ok || len(f) == 0 { if !ok || (len(f) == 0 || f == nil) {
f, ok = m.addrHeader[HeaderEnvelopeFrom] f, ok = m.addrHeader[HeaderEnvelopeFrom]
if !ok || len(f) == 0 { if !ok || (len(f) == 0 || f == nil) {
hf = false hf = false
} }
} }
if hf { if hf && (len(f) > 0 && f[0] != nil) {
mw.writeHeader(Header(HeaderFrom), f[0].String()) mw.writeHeader(Header(HeaderFrom), f[0].String())
} }