Skip to content

Runtime error: index out of range #225

@4k7

Description

@4k7

Hi,

In some cases , the "pos" value in RFC5322 class (mail/rfc5321/address.go) becomes -2, that leads to an runtime error (index out of range) in the functions peek() & next() in Parser class (mail/rfc5321/parse.go).

It happens here, if pos = -1.

s.pos = pos - 1 //- 1 // rewind to the saved position

This is line from this function (mail/rfc5321/address.go).

// mailbox  =   name-addr / addr-spec
func (s *RFC5322) mailbox() error {
	pos := s.pos // save the position
	if err := s.nameAddr(); err != nil {
		if err == errExpectingAngleAddress && s.ch != ':' { // ':' means it's a group
			// we'll attempt to parse as an email address without angle brackets
			s.addr.DisplayName = ""
			s.addr.DisplayNameQuoted = false
			s.pos = pos - 1 //- 1 // rewind to the saved position
			if s.pos > -1 {
				s.ch = s.buf[s.pos]
			}
			if err = s.Parser.mailbox(); err != nil {
				return err
			}
			s.addAddress()
		} else {
			return err
		}
	}
	return nil
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions