wneessen / go-mail

📧 Easy to use, yet comprehensive library for sending mails with Go
https://go-mail.dev
MIT License
571 stars 44 forks source link

segfault in writer because CreatePart error is ignored #138

Closed aep closed 1 year ago

aep commented 1 year ago

Description

https://github.com/wneessen/go-mail/blob/main/msgwriter.go#L240

this error is ignored, leading to a crash here

https://github.com/wneessen/go-mail/blob/main/msgwriter.go#L234C1-L235C1

goroutine 11 [running]:
bytes.(*Buffer).WriteTo(0xc00012dd10, {0x0?, 0x0?})
    /usr/local/go/src/bytes/buffer.go:252 +0x5c
io.copyBuffer({0x0, 0x0}, {0xac7900, 0xc00012dd10}, {0x0, 0x0, 0x0})
    /usr/local/go/src/io/io.go:409 +0x16e
io.Copy(...)
    /usr/local/go/src/io/io.go:386
github.com/wneessen/go-mail.(*msgWriter).writeBody(0xc0007ec770, 0xc00006b2c0, {0x9ffa26, 0x6})
    /go/pkg/mod/github.com/wneessen/go-mail@v0.3.8/msgwriter.go:330 +0x597
github.com/wneessen/go-mail.(*msgWriter).addFiles(0xc0007ec770, {0xc00012cea0, 0x6, 0x5?}, 0x1)
    /go/pkg/mod/github.com/wneessen/go-mail@v0.3.8/msgwriter.go:209 +0x6a
github.com/wneessen/go-mail.(*msgWriter).writeMsg(0xc0007ec770, 0xc00017c000)
    /go/pkg/mod/github.com/wneessen/go-mail@v0.3.8/msgwriter.go:118 +0x6bc
github.com/wneessen/go-mail.(*Msg).WriteTo(0xc00017c000, {0x7fdc9107e890?, 0xc0007ee630})
    /go/pkg/mod/github.com/wneessen/go-mail@v0.3.8/msg.go:814 +0xbc
github.com/wneessen/go-mail.(*Client).Send(0xc0001fe000, {0xc0001592b8, 0x1, 0x37?})
    /go/pkg/mod/github.com/wneessen/go-mail@v0.3.8/client_119.go:78 +0x124b
github.com/wneessen/go-mail.(*Client).DialAndSendWithContext(0xc000032052?, {0xacb778?, 0xc000068000?}, {0xc0001592b8, 0x1, 0x1})

To Reproduce

hard to do. this happens with some broken mail server that just times out.

Expected behaviour

error shouldnt be ignored

Screenshots

No response

Attempted Fixes

No response

Additional context

No response

wneessen commented 1 year ago

Thanks for the report @aep. Would you happen to have a code example that I could use to reproduce. If not, that's fine- I'll try to reproduce with a local mail server that will intentionally fail.

aep commented 1 year ago

oh as i said, its really hard to repro. but i think you can provoke it by setting the IO timeout very short.

wneessen commented 1 year ago

Thanks again for the report. I was able to reproduce the behaviour and fixed it with #139