Skip to content

Commit 42e92cf

Browse files
authored
Merge pull request #496 from wneessen/bugfix/495_mail-address-parsing
Fix vulnerability in mail address passing to the smtp client
2 parents ac1eb03 + c3c0757 commit 42e92cf

File tree

8 files changed

+356
-62
lines changed

8 files changed

+356
-62
lines changed

b64linebreaker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type base64LineBreaker struct {
4242
func (l *base64LineBreaker) Write(data []byte) (numBytes int, err error) {
4343
if l.out == nil {
4444
err = errors.New("no io.Writer set for base64LineBreaker")
45-
return
45+
return numBytes, err
4646
}
4747
if l.used+len(data) < MaxBodyLength {
4848
copy(l.line[l.used:], data)
@@ -52,25 +52,25 @@ func (l *base64LineBreaker) Write(data []byte) (numBytes int, err error) {
5252

5353
_, err = l.out.Write(l.line[0:l.used])
5454
if err != nil {
55-
return
55+
return numBytes, err
5656
}
5757
excess := MaxBodyLength - l.used
5858
l.used = 0
5959

6060
numBytes, err = l.out.Write(data[0:excess])
6161
if err != nil {
62-
return
62+
return numBytes, err
6363
}
6464

6565
_, err = l.out.Write(newlineBytes)
6666
if err != nil {
67-
return
67+
return numBytes, err
6868
}
6969

7070
var n int
7171
n, err = l.Write(data[excess:]) // recurse
7272
numBytes += n
73-
return
73+
return numBytes, err
7474
}
7575

7676
// Close finalizes the base64LineBreaker, writing any remaining buffered data and appending a newline.
@@ -85,10 +85,10 @@ func (l *base64LineBreaker) Close() (err error) {
8585
if l.used > 0 {
8686
_, err = l.out.Write(l.line[0:l.used])
8787
if err != nil {
88-
return
88+
return err
8989
}
9090
_, err = l.out.Write(newlineBytes)
9191
}
9292

93-
return
93+
return err
9494
}

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ func (c *Client) SendWithSMTPClient(client *smtp.Client, messages ...*Msg) (retu
12611261
Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
12621262
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport),
12631263
}
1264-
return
1264+
return returnErr
12651265
}
12661266

12671267
var errs []error
@@ -1279,7 +1279,7 @@ func (c *Client) SendWithSMTPClient(client *smtp.Client, messages ...*Msg) (retu
12791279
}
12801280
}
12811281

1282-
return
1282+
return returnErr
12831283
}
12841284

12851285
// auth attempts to authenticate the client using SMTP AUTH mechanisms. It checks the connection,

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ package mail
1111

1212
// VERSION indicates the current version of the package. It is also attached to the default user
1313
// agent string.
14-
const VERSION = "0.7.0"
14+
const VERSION = "0.7.1"

eml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func parseMultiPartHeader(multiPartHeader string) (header string, optional map[s
538538
headerSplit := strings.Split(multiPartHeader, ";")
539539
header = headerSplit[0]
540540
if len(headerSplit) == 1 {
541-
return
541+
return header, optional
542542
}
543543
for _, opt := range headerSplit[1:] {
544544
optString := strings.TrimLeft(opt, " ")
@@ -547,7 +547,7 @@ func parseMultiPartHeader(multiPartHeader string) (header string, optional map[s
547547
optional[optSplit[0]] = optSplit[1]
548548
}
549549
}
550-
return
550+
return header, optional
551551
}
552552

553553
// parseEMLAttachmentEmbed parses a multipart that is an attachment or embed.

msg.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,10 +1495,12 @@ func (m *Msg) GetSender(useFullAddr bool) (string, error) {
14951495
return "", ErrNoFromAddress
14961496
}
14971497
}
1498-
if useFullAddr {
1499-
return from[0].String(), nil
1498+
1499+
addr := from[0]
1500+
if !useFullAddr {
1501+
addr.Name = ""
15001502
}
1501-
return from[0].Address, nil
1503+
return addr.String(), nil
15021504
}
15031505

15041506
// GetRecipients returns a list of the currently set "TO", "CC", and "BCC" addresses for the Msg.
@@ -1522,7 +1524,8 @@ func (m *Msg) GetRecipients() ([]string, error) {
15221524
continue
15231525
}
15241526
for _, r := range addresses {
1525-
rcpts = append(rcpts, r.Address)
1527+
r.Name = ""
1528+
rcpts = append(rcpts, r.String())
15261529
}
15271530
}
15281531
if len(rcpts) <= 0 {

0 commit comments

Comments
 (0)