This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
forked from go-gomail/gomail
-
Notifications
You must be signed in to change notification settings - Fork 77
Segmentation fault when attaching non-existent file #48
Comments
@chmike Could you provide more details like a stack trace or other console output and an example of the code that you used? |
I created a small program that reproduce the segmentation fault. When the attachment with non-existing file is last, I get an error. When there is a subsequent attachment of an existing file, I get a segmentation fault. The following code produce a segmentation fault. It requires that a file named "exist.jpg" is in the working directory: package main
import (
"github.com/go-mail/mail"
)
func main() {
m := mail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetHeader("To", "[email protected]")
m.SetHeader("Subject", "Test mail")
m.SetBody("text/plain", "This is a test mail")
m.Attach("doesntExist.jpg")
m.Attach("exist.jpg")
d := mail.Dialer{Host: "localhost", Port: 25, StartTLSPolicy: mail.NoStartTLS}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
} This is the output with the stack trace: panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x646fef]
goroutine 1 [running]:
github.com/go-mail/mail.(*base64LineWriter).Write(0xc000162aa0, 0xc0000b2938, 0x400, 0x400, 0x0, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/writeto.go:299 +0xdf
encoding/base64.(*encoder).Write(0xc0000b2900, 0xc00016c000, 0x30b9, 0x8000, 0x0, 0x0, 0x0)
/usr/local/go/src/encoding/base64/base64.go:217 +0x5fc
io.copyBuffer(0x7fce5fa0d0a0, 0xc0000b2900, 0x6f4fc0, 0xc000142fa8, 0xc00016c000, 0x8000, 0x8000, 0x0, 0x0, 0x0)
/usr/local/go/src/io/io.go:404 +0x457
io.Copy(0x7fce5fa0d0a0, 0xc0000b2900, 0x6f4fc0, 0xc000142fa8, 0x0, 0x0, 0x0)
/usr/local/go/src/io/io.go:364 +0x97
github.com/go-mail/mail.fileFromFilename.func1(0x7fce5fa0d0a0, 0xc0000b2900, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/message.go:327 +0x13d
github.com/go-mail/mail.(*messageWriter).writeBody(0xc0000784e0, 0xc00000c300, 0x6b404b, 0x6)
/home/xxx/go/src/github.com/go-mail/mail/writeto.go:271 +0x227
github.com/go-mail/mail.(*messageWriter).addFiles(0xc0000784e0, 0xc000010710, 0x2, 0x2, 0x1)
/home/xxx/go/src/github.com/go-mail/mail/writeto.go:148 +0x202
github.com/go-mail/mail.(*messageWriter).writeMessage(0xc0000784e0, 0xc0000d0000)
/home/xxx/go/src/github.com/go-mail/mail/writeto.go:53 +0x3da
github.com/go-mail/mail.(*Message).WriteTo(0xc0000d0000, 0x7fce5fa09020, 0xc00000c520, 0x0, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/writeto.go:17 +0xc7
github.com/go-mail/mail.(*smtpSender).Send(0xc000082c30, 0xc000016530, 0x10, 0xc000010800, 0x1, 0x1, 0x6f4dc0, 0xc0000d0000, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/smtp.go:262 +0x676
github.com/go-mail/mail.send(0x7fce5fa09000, 0xc000082c30, 0xc0000d0000, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/send.go:57 +0x269
github.com/go-mail/mail.Send(0x7fce5fa09000, 0xc000082c30, 0xc0000c5ee0, 0x1, 0x1, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/send.go:38 +0xd7
github.com/go-mail/mail.(*Dialer).DialAndSend(0xc0000b8080, 0xc0000c5ee0, 0x1, 0x1, 0x0, 0x0)
/home/xxx/go/src/github.com/go-mail/mail/smtp.go:210 +0x17e
main.main()
/home/xxx/go/src/testmail/main.go:16 +0x3c0 |
I must add that the mail is sent (when providing a valid address). So the segmentation fault is after sending the mail. But the mail is truncated where the missing file should start. It shouldn’t have send this mail. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I attached a file to a message with the instruction ˋm.Attach(filename)ˋ, but there was no file with that name. The
DialAndSend
instruction was aborted with a segmentation fault error. I expect to get an error message instead. The file name was for a png file in case it matters.The text was updated successfully, but these errors were encountered: