Skip to content

Runtime error: index out of range #3

Description

@k33nice

I've got runtime error

Oct 26 07:45:18: panic: runtime error: index out of range
Oct 26 07:45:18: goroutine 80639 [running]:
Oct 26 07:45:18: github.com/phalaaxx/milter.(*MilterSession).Process(0xc4210278c0, 0xc4210360a0, 0x0, 0x0, 0x0, 0x0)
Oct 26 07:45:18: /go/src/github.com/phalaaxx/milter/session.go:116 +0x48b

It's caused by bounds check in encoding/binary package.

func (bigEndian) Uint16(b []byte) uint16 {
	_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
	return uint16(b[1]) | uint16(b[0])<<8
}

Perhaps it would be better retrun error if msg.Data length less than needed.

...
		Hostname := ReadCString(msg.Data)
		msg.Data = msg.Data[len(Hostname)+1:]
		// get protocol family
		ProtocolFamily := msg.Data[0]
		msg.Data = msg.Data[1:]
		// get port
		Port := binary.BigEndian.Uint16(msg.Data)
...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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